X = (Y>>7 |1)/16777216.0 ;
/*
Y is long..X is float..
the line will take teh value of Y and shift it 7 times then what?
*/
Printable View
X = (Y>>7 |1)/16777216.0 ;
/*
Y is long..X is float..
the line will take teh value of Y and shift it 7 times then what?
*/
i now get some more..
he shift then or it with 1..but why 1 specificly?he wants to grant that teh least bit is 1!! why is that?
How are we supposed to know when we don't even know what the program is supposed to do?Quote:
Originally Posted by deepinlife
Regards,
Paul McKenzie
class randam_generator
{
/*Marse and roberts randrom generator algorthim*/
private:
const unsigned long MODLUS = 2147483647 ;
const unsigned short MULT1 = 24112 ;
const unsigned short MULT2 = 26143 ;
const long zrng[]={1973272912};
public:
float lcgrand(int stram)
{
long zi , lowprd , hi3 ;
zi =zrng[ stream ];
lowprd =(zi & 65535 )* MULT1 ;
hi31 = (zi >> 16 )*MULT1 +(lowprd >>16 );
zi =( (lowprd & 65535) - MODUS )+ ( (hi31 & 32767)<<16)+(hi31>>15);
if( zi <0)zi += MODUS ;
lowprd =(zi &65535)*MULT2;
hi31 =(zi >>16)*MULT2 +(lowprd >> 16 );
zi = ( (lowprd & 65535)-MODLUS) +((hi31 &32767)<<16)+(hi31>>15);
if(zi<0) zi+=MODLUS;
zrng[stream] = zi;
return (zi>>7|1)/16777216.0;
}
};
So, it's an algorithm to generate pseudo-random numbers. If you don't understand the algorithm, search the web for the RNG's formula.
What this particular line of code does is:
- Y >> 7 : shifts Y to the left, 7 bit positions (that means Y is divided by 128)
- (Y >> 7) | 1 : least significant bit of the result is set to one (if wasn't already)
- ((Y >> 7) | 1) / 16777216.0 : the result (which is definitelly an odd number) is devided by a constant
thanks