Elementary cellular automaton/Random number generator: Difference between revisions

m
→‎{{header|Haskell}}: Minor reduction. Applied Ormolu.
No edit summary
m (→‎{{header|Haskell}}: Minor reduction. Applied Ormolu.)
Line 221:
Assume the comonadic solution given at [[Elementary cellular automaton#Haskell]] is packed in a module <code>CellularAutomata</code>
 
<lang Haskell>import CellularAutomata (runCAfromList, rule, fromListrunCA)
import Data.List (unfoldr)
import Control.Comonad
import Data.List (unfoldr)
 
rnd = fromBits <$> unfoldr (pure . splitAt 8) bits
where size = 80
size = 80
bits = extract <$> runCA (rule 30) (fromList (1:replicate size 0))
bits =
extract
<$> runCA
(rule 30)
bits = extract <$> runCA (rule 30) (fromList (1 : replicate size 0))
 
fromBits = foldl (\res(+) x. ->(2 2*res + x)) 0</lang>
 
{{Out}}
9,655

edits