Elementary cellular automaton/Random number generator: Difference between revisions

→‎{{header|Haskell}}: Added Haskell solution
m (Added the Sidef language)
(→‎{{header|Haskell}}: Added Haskell solution)
Line 150:
44</pre>
Run-time: less than two seconds with the ldc2 compiler.
 
=={{header|Haskell}}==
 
Assume the comonadic solution given at [[Elementary cellular automaton#Haskell]] is packed in a module <code>CellularAutomata</code>
 
<lang Haskell>import CellularAutomata (runCA, rule, fromList)
import Data.List (unfoldr)
import Control.Comonad (extract)
 
rnd = fromBits <$> unfoldr (pure . splitAt 8) bits
where size = 80
bits = extract <$> runCA (rule 30) (fromList (1:replicate size 0))
fromBits = foldl (\res x -> 2*res + x) 0</lang>
 
{{Out}}
<pre>λ> take 10 rnd
[220,197,147,174,117,97,149,171,240,241]</pre>
 
=={{header|J}}==
Anonymous user