module Reloto.Random where
import Data.Bool
import Data.Eq (Eq(..))
import Data.Foldable (all)
import Data.Int (Int)
import Data.List ((++), length, nub, sort)
import Data.Ord (Ord(..))
import Prelude (Integer, Num(..), undefined, (^))
import Reloto.Bits
import Reloto.Combin
import Reloto.Sequence
equiprobableBits :: Integer -> Int
equiprobableBits :: Integer -> Int
equiprobableBits Integer
n | Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
bInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
-Integer
1 = Int
b
| Bool
otherwise = Int
bInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1
where b :: Int
b = Integer -> Int
bitSize Integer
n
randomOfCombin :: Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin :: Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
n Integer
k [Integer]
xs
| Integer
0Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n, Integer
0Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
k, Integer
kInteger -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n
, (Integer -> Bool) -> [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Integer
x -> Integer
1Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
xBool -> Bool -> Bool
&&Integer
xInteger -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n) [Integer]
xs
, [Integer] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Integer] -> [Integer]
forall a. Eq a => [a] -> [a]
nub [Integer]
xs) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
xs =
if Integer -> Int
bitSize Integer
rank Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
epBits
then Int
epBits Int -> Integer -> [Bool]
`bitsOfInteger` Integer
rank
else []
where rank :: Integer
rank = Integer -> [Integer] -> Integer
forall i. Integral i => i -> [i] -> i
rankOfCombin Integer
n ([Integer] -> [Integer]
forall a. Ord a => [a] -> [a]
sort [Integer]
xs)
epBits :: Int
epBits = Integer -> Int
equiprobableBits (Integer
nInteger -> Integer -> Integer
forall i. Integral i => i -> i -> i
`nCk`Integer
k)
randomOfCombin Integer
_ Integer
_ [Integer]
_ = [Bool]
forall a. HasCallStack => a
undefined
randomOfSequence :: Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence :: Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence Integer
n Integer
k [Integer]
xs
| Integer
0Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n, Integer
0Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
k, Integer
kInteger -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n
, (Integer -> Bool) -> [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Integer
x -> Integer
1Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
xBool -> Bool -> Bool
&&Integer
xInteger -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<=Integer
n) [Integer]
xs
, [Integer] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Integer] -> [Integer]
forall a. Eq a => [a] -> [a]
nub [Integer]
xs) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
xs =
if Integer -> Int
bitSize Integer
rank Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
epBits
then Int
epBits Int -> Integer -> [Bool]
`bitsOfInteger` Integer
rank
else []
where rank :: Integer
rank = Integer -> [Integer] -> Integer
forall i. Integral i => i -> [i] -> i
rankOfSequence Integer
n ([Integer] -> [Integer]
forall a. Ord a => [a] -> [a]
sort [Integer]
xs)
epBits :: Int
epBits = Integer -> Int
equiprobableBits (Integer
nInteger -> Integer -> Integer
forall i. Integral i => i -> i -> i
`nAk`Integer
k)
randomOfSequence Integer
_ Integer
_ [Integer]
_ = [Bool]
forall a. HasCallStack => a
undefined
randomOf6aus49 :: (Integer,Integer,Integer,Integer,Integer,Integer) -> Integer -> [Bool]
randomOf6aus49 :: (Integer, Integer, Integer, Integer, Integer, Integer)
-> Integer -> [Bool]
randomOf6aus49 (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5,Integer
n6) Integer
nc = Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
49 Integer
6 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5,Integer
n6] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
10 Integer
1 [Integer
nc]
randomOfEuroMillions :: (Integer,Integer,Integer,Integer,Integer) -> (Integer,Integer) -> [Bool]
randomOfEuroMillions :: (Integer, Integer, Integer, Integer, Integer)
-> (Integer, Integer) -> [Bool]
randomOfEuroMillions (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5) (Integer
nc1,Integer
nc2) = Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
50 Integer
5 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
12 Integer
2 [Integer
nc1,Integer
nc2]
randomOfOrderedEuroMillions :: (Integer,Integer,Integer,Integer,Integer) -> (Integer,Integer) -> [Bool]
randomOfOrderedEuroMillions :: (Integer, Integer, Integer, Integer, Integer)
-> (Integer, Integer) -> [Bool]
randomOfOrderedEuroMillions (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5) (Integer
nc1,Integer
nc2) = Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence Integer
50 Integer
5 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence Integer
12 Integer
2 [Integer
nc1,Integer
nc2]
randomOfFrenchLoto :: (Integer,Integer,Integer,Integer,Integer) -> Integer -> [Bool]
randomOfFrenchLoto :: (Integer, Integer, Integer, Integer, Integer) -> Integer -> [Bool]
randomOfFrenchLoto (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5) Integer
nc = Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
49 Integer
5 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
10 Integer
1 [Integer
nc]
randomOfOrderedFrenchLoto :: (Integer,Integer,Integer,Integer,Integer) -> Integer -> [Bool]
randomOfOrderedFrenchLoto :: (Integer, Integer, Integer, Integer, Integer) -> Integer -> [Bool]
randomOfOrderedFrenchLoto (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5) Integer
nc = Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence Integer
49 Integer
5 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfSequence Integer
10 Integer
1 [Integer
nc]
randomOfSwissLoto :: (Integer,Integer,Integer,Integer,Integer,Integer) -> Integer -> [Bool]
randomOfSwissLoto :: (Integer, Integer, Integer, Integer, Integer, Integer)
-> Integer -> [Bool]
randomOfSwissLoto (Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5,Integer
n6) Integer
nc = Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
42 Integer
6 [Integer
n1,Integer
n2,Integer
n3,Integer
n4,Integer
n5,Integer
n6] [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++
Integer -> Integer -> [Integer] -> [Bool]
randomOfCombin Integer
6 Integer
1 [Integer
nc]