[Haskell-cafe] Random numbers / monads - beginner question
Claude Heiland-Allen
claudiusmaximus at goto10.org
Thu May 8 06:47:59 EDT 2008
Madoc wrote:
> Given a list of numbers, I want to modify each of those numbers by adding a
> random offset. However, each such modified number shall stay within certain
> bounds, given by the integers minValue and maxValue. After that, I want to
> continue computation with the resulting list of type [Int].
Personally, I'd do something like this, isolate the IO code outside the
algorithm to keep the algorithm pure:
modify' :: Int -> Int -> Int
modify' offset a = normalize (a + offset)
generateInfiniteListOfRandomNumbers :: IO [Int]
-- implementation left as an exercise
main = do
randomNumbers <- generateInfiniteListOfRandomNumbers
print $ zipWith modify' randomNumbers [0, 200, 400, 600, 800, 1000]
hope this helps,
Claude
--
http://claudiusmaximus.goto10.org
More information about the Haskell-Cafe
mailing list