Linear congruential generator: Difference between revisions
Content added Content deleted
No edit summary |
(Add dc(1), the classic Unix calculator language. I hope that some F# programmer will fix the F# code.) |
||
Line 156: | Line 156: | ||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
=={{header|dc}}== |
|||
''dc'' has no bitwise operations, so this program uses the modulus operator (<code>2147483648 %</code>) and division (<code>65536 /</code>). Fortunately, ''dc'' numbers cannot overflow to negative, so the modulus calculation involves only non-negative integers. |
|||
For BSD rand(): <lang dc>[* |
|||
* lrx -- (random number from 0 to 2147483647) |
|||
* |
|||
* Returns a number from the BSD rand() sequence. |
|||
* Seeded by storing a seed in register R. |
|||
*]sz |
|||
[lR 1103515245 * 12345 + 2147483648 % d sR]sr |
|||
[* Set seed to 1, then print the first 3 random numbers. *]sz |
|||
1 sR |
|||
lrx psz lrx psz lrx psz</lang> |
|||
<pre>1103527590 |
|||
377401575 |
|||
662824084</pre> |
|||
For Microsoft rand(): <lang dc>[* |
|||
* lrx -- (random number from 0 to 32767) |
|||
* |
|||
* Returns a number from the Microsoft rand() sequence. |
|||
* Seeded by storing a seed in register R. |
|||
*]sz |
|||
[lR 214013 * 2531011 + 2147483648 % d sR 65536 /]sr |
|||
[* Set seed to 1, then print the first 3 random numbers. *]sz |
|||
1 sR |
|||
lrx psz lrx psz lrx psz</lang> |
|||
<pre>41 |
|||
18467 |
|||
6334</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |