Pseudo-random numbers/Splitmix64: Difference between revisions
Content added Content deleted
(add PicoLisp) |
|||
Line 334: | Line 334: | ||
{20027,19892,20073,19978,20030} |
{20027,19892,20073,19978,20030} |
||
</pre> |
</pre> |
||
=={{header|PicoLisp}}== |
|||
<lang PicoLisp>(zero *Split) # global state |
|||
(de mod64 (N) |
|||
(& N `(hex "FFFFFFFFFFFFFFFF")) ) |
|||
(de mod64+ (A B) |
|||
(mod64 (+ A B)) ) |
|||
(de mod64* (A B) |
|||
(mod64 (* A B)) ) |
|||
(de roundf (N) # rounds down |
|||
(/ N (** 10 *Scl)) ) |
|||
(de nextSplit () |
|||
(setq *Split (mod64+ *Split `(hex "9e3779b97f4a7c15"))) |
|||
(let Z *Split |
|||
(setq |
|||
Z (mod64* `(hex "bf58476d1ce4e5b9") (x| Z (>> 30 Z))) |
|||
Z (mod64* `(hex "94d049bb133111eb") (x| Z (>> 27 Z))) ) |
|||
(x| Z (>> 31 Z)) ) ) |
|||
(prinl "First 5 numbers:") |
|||
(setq *Split 1234567) |
|||
(do 5 |
|||
(println (nextSplit)) ) |
|||
(prinl "The counts for 100,000 repetitions are:") |
|||
(scl 12) |
|||
(off R) |
|||
(setq *Split 987654321) |
|||
(do 100000 |
|||
(accu |
|||
'R |
|||
(roundf (* 5 (*/ (nextSplit) 1.0 18446744073709551616))) |
|||
1 ) ) |
|||
(mapc println (sort R))</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 5 numbers: |
|||
6457827717110365317 |
|||
3203168211198807973 |
|||
9817491932198370423 |
|||
4593380528125082431 |
|||
16408922859458223821 |
|||
The counts for 100,000 repetitions are: |
|||
(0 . 20027) |
|||
(1 . 19892) |
|||
(2 . 20073) |
|||
(3 . 19978) |
|||
(4 . 20030) |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |