Skip to content

Instantly share code, notes, and snippets.

@dripolles
Last active August 29, 2015 13:57
Show Gist options
  • Save dripolles/9666469 to your computer and use it in GitHub Desktop.
Save dripolles/9666469 to your computer and use it in GitHub Desktop.
1HaskellADay 2014/03/20
-- http://codepad.org/QomzEZSD
import System.Random
import Control.Arrow
addNoise :: (Num a, Random a) => a -> [a] -> StdGen -> ([a], StdGen)
addNoise x l gen = let
range = ((id &&& negate) . abs) x
noised = zipWith (+) l (randomRs range gen)
in (noised, fst $ split gen)
-- It can be done in a line, but it's uglier
addNoise' x l gen =
(zipWith (+) l (randomRs (((id &&& negate) . abs) x) gen), fst $ split gen)
main = do
gen <- getStdGen
let (l, gen') = addNoise 5 [1,1,1,1,1,1] gen :: ([Int], StdGen)
print (l, gen')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment