Linear congruential generator: Difference between revisions
Content added Content deleted
(Establish a task "to replicate two historic random number generators." There are still some notes about missing text and wiki formatting, where I intend to fill in later.) |
(GP) |
||
Line 1: | Line 1: | ||
{{draft task|Randomness}} |
{{draft task|Randomness}} |
||
The [[wp:linear congruential generator|linear congruential generator]] is a very simple example of a [[random number generator]]. All linear congruential generators use this formula: |
The [[wp:linear congruential generator|linear congruential generator]] is a very simple example of a [[wp:Random number generation|random number generator]]. All linear congruential generators use this formula: |
||
* <math>r_{n + 1} = a \times r_n + c \pmod m</math> |
* <math>r_{n + 1} = a \times r_n + c \pmod m</math> |
||
Line 33: | Line 33: | ||
(Here should be some sample numbers for a few seeds, so that one who solves this task can check if one's numbers matches these samples.) |
(Here should be some sample numbers for a few seeds, so that one who solves this task can check if one's numbers matches these samples.) |
||
=={{header|PARI/GP}}== |
|||
Note that up to PARI/GP version 2.3.0, <code>random()</code> used linear congruential generators. |
|||
<lang parigp>BSDseed=Mod(1,1<<31); |
|||
MSFTseed=Mod(1,1<<31); |
|||
BSD()=BSDseed=1103515245*BSDseed+12345;lift(BSDseed); |
|||
MSFT()=MSFTseed=214013*MSFTseed+2531011;lift(MSFTseed)%(1<<31);</lang> |