Elementary cellular automaton/Random number generator: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Haskell}}: Minor reduction. Applied Ormolu.) |
||
Line 221: | Line 221: | ||
Assume the comonadic solution given at [[Elementary cellular automaton#Haskell]] is packed in a module <code>CellularAutomata</code> |
Assume the comonadic solution given at [[Elementary cellular automaton#Haskell]] is packed in a module <code>CellularAutomata</code> |
||
<lang Haskell>import CellularAutomata ( |
<lang Haskell>import CellularAutomata (fromList, rule, runCA) |
||
⚫ | |||
import Control.Comonad |
import Control.Comonad |
||
⚫ | |||
rnd = fromBits <$> unfoldr (pure . splitAt 8) bits |
rnd = fromBits <$> unfoldr (pure . splitAt 8) bits |
||
where |
where |
||
size = 80 |
|||
⚫ | |||
bits = |
|||
extract |
|||
<$> runCA |
|||
(rule 30) |
|||
⚫ | |||
fromBits = foldl ( |
fromBits = foldl ((+) . (2 *)) 0</lang> |
||
{{Out}} |
{{Out}} |