summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2018-06-30 10:14:47 -0700
committerBen Sima <ben@bsima.me>2018-06-30 10:14:47 -0700
commite2e345520ca8ffcaece19d27007e87dcfa02d864 (patch)
tree594cca6723c90c28769fd9ddba51faea63eeb153
parent4742b80bf27c9befce14546210ce89667e9d1169 (diff)
Split `run` into a helper function and use a new random gen every time
-rw-r--r--simspace/Main.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/simspace/Main.hs b/simspace/Main.hs
index 07d2705..229bba4 100644
--- a/simspace/Main.hs
+++ b/simspace/Main.hs
@@ -2,7 +2,7 @@ module Main where
import System.Environment
import Control.Monad
-import System.Random (getStdGen, randomRs)
+import System.Random (newStdGen, randomRs)
import Data.List.Split
main :: IO ()
@@ -12,10 +12,17 @@ main = do
[] -> putStrLn "Needs one argument"
(n:_) -> run (read n :: Int)
+-- | Run the cellular automata with a random seed.
run :: Int -> IO ()
run n = do
- g <- getStdGen
+ g <- newStdGen
let init = take n $ randomRs (0,1) g
+ run' init
+
+-- | Version of 'run' that allows for entering your own initial seed.
+run' :: [Int] -> IO ()
+run' init = do
+ let n = length init
let zeros = take n $ repeat 0
let result = takeWhile' (/= zeros) $ chunksOf n $ compute n init
forM_ result $ \r -> putStrLn $ show r