2 module Htirage.Draw where
5 import Prelude (Integer, Integral(..), Num(..))
6 import Data.List (length, map)
10 import Htirage.Sequence
12 -- | @unorderedDraw k xs bs@ retourne 'k' choix (sans ordre ni répétition) parmi 'xs'
13 -- déterminés par l’entropie 'bs'.
14 unorderedDraw :: Integer -> [a] -> [Bool] -> [a]
15 unorderedDraw k xs bs = map fromInteger (combinOfRank n k r) `permute` xs
16 where n = toInteger (length xs)
17 r = randomIntegerOfBits (n`nCk`k) bs
19 -- | @orderedDraw k xs bs@ retourne 'k' choix (avec ordre mais sans répétition) parmi 'xs'
20 -- déterminés par l’entropie 'bs'.
21 orderedDraw :: Integer -> [a] -> [Bool] -> [a]
22 orderedDraw k xs bs = map fromInteger (sequenceOfRank n k r) `permute` xs
23 where n = toInteger (length xs)
24 r = randomIntegerOfBits (n`nAk`k) bs