Pseudo-random numbers/Splitmix64: Difference between revisions

→‎{{header|Haskell}}: added solution
(→‎{{header|Haskell}}: added solution)
Line 376:
4 : 20030
</pre>
 
=={{header|Haskell}}==
 
<lang haskell>import Data.Bits
import Data.Word
import Data.List
 
next :: Word64 -> (Word64, Word64)
next state = f4 $ state + 0x9e3779b97f4a7c15
where
f1 z = (z `xor` (z `shiftR` 30)) * 0xbf58476d1ce4e5b9
f2 z = (z `xor` (z `shiftR` 27)) * 0x94d049bb133111eb
f3 z = z `xor` (z `shiftR` 31)
f4 s = ((f3 . f2 . f1) s, s)
 
randoms = unfoldr (pure . next)
 
toFloat n = fromIntegral n / (2^64 - 1)</lang>
 
<pre>λ> mapM_ print $ take 5 $ randoms 1234567
6457827717110365317
3203168211198807973
9817491932198370423
4593380528125082431
16408922859458223821
 
λ> let hist = map length . group . sort
λ> hist . take 100000 $ (floor . (*5) . toFloat) <$> (randoms 987654321)
[20027,19892,20073,19978,20030]</pre>
 
=={{header|Julia}}==
Anonymous user