LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Super period (https://www.linuxquestions.org/questions/programming-9/super-period-4175496642/)

l0p3n 03-01-2014 07:43 AM

Super period
 
http://en.wikipedia.org/wiki/Linear_..._in_common_use

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

ntubski 03-03-2014 08:38 PM

You have your bit counts a bit mixed up.
Code:

A 48 bit random number, the internal value Xn
0011 0111  0000 1010  0111 1101  1001 0000  0111 1101  1110 1011

32 high bits, what is returned from Math.random()
0011 0111  0000 1010  0111 1101  1001 0000

Note that the lower 16 bits are not thrown away, they just aren't given to the application (caller of random()).

l0p3n 03-04-2014 12:47 AM

If I have understood this correctly the 48 bits will be saved and used when generating the next random number. But what is returned as the random number to the calling application are the 32 higher-order bits of the generated number?


All times are GMT -5. The time now is 08:38 PM.