Name:
Anonymous
2010-09-13 8:38
Create a sequence of random integers with the following given: max, average, length
Example, with m = 7, a = 4, l = 5, you get [ 5, 2, 2, 4, 7 ].
Name:
Anonymous
2010-09-13 10:17
replicateM length $ randomRIO (min, max)
Name:
Anonymous
2010-09-13 10:49
>>8
Boy, did I not read the specification there.
Oh, well.
getAvgRand len avg max = fix (\f (x:xs) -> x >>= maybe (f xs) return) $ map (\x -> sequence x >>= \y -> if (fromIntegral $ sum y) / fromIntegral len == avg then return (Just y) else return Nothing) (repeat $ take len $ repeat $ randomRIO (0, max))