Click to See Complete Forum and Search --> : can anyone explain this line!
deepinlife
October 14th, 2005, 01:36 AM
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?
*/
deepinlife
October 14th, 2005, 01:42 AM
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?
Paul McKenzie
October 14th, 2005, 02:20 AM
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?
Regards,
Paul McKenzie
deepinlife
October 14th, 2005, 03:19 AM
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;
}
};
cilu
October 14th, 2005, 03:42 AM
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
deepinlife
October 14th, 2005, 07:18 AM
thanks
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.