|
-
October 14th, 2005, 01:36 AM
#1
can anyone explain this line!
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?
*/
-
October 14th, 2005, 01:42 AM
#2
Re: can anyone explain this line!
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?
-
October 14th, 2005, 02:20 AM
#3
Re: can anyone explain this line!
 Originally Posted by deepinlife
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
-
October 14th, 2005, 03:19 AM
#4
Re: can anyone explain this line!
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;
}
};
-
October 14th, 2005, 03:42 AM
#5
Re: can anyone explain this line!
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
-
October 14th, 2005, 07:18 AM
#6
Re: can anyone explain this line!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|