]> Git — Sourcephile - reloto.git/blob - Htirage/Draw.hs
cee7f44121720f701f7df8b43cea962ce8d773cb
[reloto.git] / Htirage / Draw.hs
1 -- | Tirages.
2 module Htirage.Draw where
3
4 import Data.Bool
5 import Prelude (Integer, Integral(..), Num(..))
6 import Data.List (length, map)
7
8 import Htirage.Bits
9 import Htirage.Combin
10 import Htirage.Sequence
11
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
18
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