module Reloto.Draw where
import Data.Bool
import Prelude (Integer, Integral(..), Num(..))
import Data.List (length, map)
import Reloto.Bits
import Reloto.Combin
import Reloto.Sequence
unorderedDraw :: Integer -> [a] -> [Bool] -> [a]
unorderedDraw :: Integer -> [a] -> [Bool] -> [a]
unorderedDraw Integer
k [a]
xs [Bool]
bs = (Integer -> Int) -> [Integer] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Integer -> Integer -> [Integer]
forall i. Integral i => i -> i -> i -> [i]
combinOfRank Integer
n Integer
k Integer
r) [Int] -> [a] -> [a]
forall a. [Int] -> [a] -> [a]
`permute` [a]
xs
where n :: Integer
n = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs)
r :: Integer
r = Integer -> [Bool] -> Integer
randomIntegerOfBits (Integer
nInteger -> Integer -> Integer
forall i. Integral i => i -> i -> i
`nCk`Integer
k) [Bool]
bs
orderedDraw :: Integer -> [a] -> [Bool] -> [a]
orderedDraw :: Integer -> [a] -> [Bool] -> [a]
orderedDraw Integer
k [a]
xs [Bool]
bs = (Integer -> Int) -> [Integer] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Integer -> Integer -> [Integer]
forall i. Integral i => i -> i -> i -> [i]
sequenceOfRank Integer
n Integer
k Integer
r) [Int] -> [a] -> [a]
forall a. [Int] -> [a] -> [a]
`permute` [a]
xs
where n :: Integer
n = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs)
r :: Integer
r = Integer -> [Bool] -> Integer
randomIntegerOfBits (Integer
nInteger -> Integer -> Integer
forall i. Integral i => i -> i -> i
`nAk`Integer
k) [Bool]
bs