Pseudozufallszahlen (II)

Liste von Zufallszahlen aus gegebenem Bereich:

import System.Random ; import Control.Monad
zufs :: Int -> (Int,Int) -> IO [Int]
zufs n (lo,hi) = 
    forM [ 1 .. n ] $ \ k -> randomRIO (lo,hi)
eine zufällige Permutation:
perm :: [a] -> IO [a]
perm xs = if null xs then return [] else do
    i <- randomRIO (0, length xs - 1)
    let ( pre, this : post ) = splitAt i xs
    ys <- perm $ pre ++ post
    return $ this : ys



Johannes Waldmann 2011-01-18