Linear congruential generator: Difference between revisions
Content added Content deleted
m (seed_n => state_n) |
(In the task description, add the range of BSD and Microsoft rand_n, attempting to prohibit solutions like the F# code that yields numbers out of range.) |
||
Line 22: | Line 22: | ||
* <math>state_{n + 1} = 1103515245 \times state_n + 12345 \pmod{2^{31}}</math> |
* <math>state_{n + 1} = 1103515245 \times state_n + 12345 \pmod{2^{31}}</math> |
||
* <math>rand_n = state_n</math> |
* <math>rand_n = state_n</math> |
||
* <math>rand_n</math> is in range 0 to 2147483647. |
|||
Microsoft formula: |
Microsoft formula: |
||
Line 27: | Line 28: | ||
* <math>state_{n + 1} = 214013 \times state_n + 2531011 \pmod{2^{31}}</math> |
* <math>state_{n + 1} = 214013 \times state_n + 2531011 \pmod{2^{31}}</math> |
||
* <math>rand_n = state_n \div 2^{16}</math> |
* <math>rand_n = state_n \div 2^{16}</math> |
||
* <math>rand_n</math> is in range 0 to 32767. |
|||
The BSD formula was so awful that FreeBSD switched to a different formula. More info is at [[Random number generator (included)#C]]. |
The BSD formula was so awful that FreeBSD switched to a different formula. More info is at [[Random number generator (included)#C]]. |