Skip to content

Instantly share code, notes, and snippets.

@Jamil
Created December 23, 2016 22:16
Show Gist options
  • Select an option

  • Save Jamil/83cefe7c323727ecd7f7a6cb14046336 to your computer and use it in GitHub Desktop.

Select an option

Save Jamil/83cefe7c323727ecd7f7a6cb14046336 to your computer and use it in GitHub Desktop.
Generate a string given a bigram map, a random number generator, a seed, and an initial token
gen :: [(String, [String])] -> (Int -> Int) -> Int -> String -> [String]
gen lbs rand seed x = case lookup x lbs of
Just [] -> []
Just followers -> nxt:(gen lbs rand index nxt)
where nxt = followers !! (index `mod` (length followers))
index = rand seed
Nothing -> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment