Personal tools

Examples/Random list

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(more code)
 
(looks like someone used two different names for the same thing)
Line 10: Line 10:
 
main = do
 
main = do
 
seed <- newStdGen
 
seed <- newStdGen
let rs = randomify 10 seed
+
let rs = randomlist 10 seed
 
print rs
 
print rs
   

Revision as of 17:33, 2 May 2007


Generate a random list of numbers, without using the System.Random.randoms method:

import System.Random
import Data.List
 
main = do
    seed  <- newStdGen
    let rs = randomlist 10 seed
    print rs
 
randomlist :: Int -> StdGen -> [Int]
randomlist n = take n . unfoldr (Just . random)