Pseudo-random numbers/Splitmix64: Difference between revisions
Content added Content deleted
(Added Sidef) |
(Added Forth entry) |
||
Line 216: | Line 216: | ||
H{ { 0 20027 } { 1 19892 } { 2 20073 } { 3 19978 } { 4 20030 } } |
H{ { 0 20027 } { 1 19892 } { 2 20073 } { 3 19978 } { 4 20030 } } |
||
</pre> |
</pre> |
||
=={{header|Forth}}== |
|||
{{works with|gforth|0.7.3}} |
|||
<lang forth>variable rnd-state |
|||
: rnd-base-op ( z factor shift -- u ) 2 pick swap rshift rot xor * ; |
|||
: rnd-next ( -- u ) |
|||
$9e3779b97f4a7c15 rnd-state +! |
|||
rnd-state @ |
|||
$bf58476d1ce4e5b9 #30 rnd-base-op |
|||
$94d049bb133111eb #27 rnd-base-op |
|||
#1 #31 rnd-base-op |
|||
; |
|||
#1234567 rnd-state ! |
|||
cr |
|||
rnd-next u. cr |
|||
rnd-next u. cr |
|||
rnd-next u. cr |
|||
rnd-next u. cr |
|||
rnd-next u. cr |
|||
: rnd-next-float ( -- f ) |
|||
rnd-next 0 d>f 0 1 d>f f/ |
|||
; |
|||
create counts 0 , 0 , 0 , 0 , 0 , |
|||
: counts-fill |
|||
#987654321 rnd-state ! |
|||
100000 0 do |
|||
rnd-next-float 5.0e0 f* f>d drop cells counts + dup @ 1+ swap ! |
|||
loop |
|||
; |
|||
: counts-disp |
|||
5 0 do |
|||
cr i . ': emit bl emit |
|||
counts i cells + @ . |
|||
loop cr |
|||
; |
|||
counts-fill counts-disp</lang> |
|||
{{out}} |
|||
<pre>6457827717110365317 |
|||
3203168211198807973 |
|||
9817491932198370423 |
|||
4593380528125082431 |
|||
16408922859458223821 |
|||
0 : 20027 |
|||
1 : 19892 |
|||
2 : 20073 |
|||
3 : 19978 |
|||
4 : 20030 |
|||
ok</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |