Use Skein-256 as PRNG
This commit is contained in:
parent
f396586033
commit
da98d65cdd
@ -1,10 +1,5 @@
|
|||||||
module Alea.List where
|
module Alea.List where
|
||||||
|
|
||||||
-- Remove the nth element of a list. (0-indexed)
|
|
||||||
-- RemoveAt 2 "abc" == ('c', "ab")
|
|
||||||
removeAt :: Int -> [a] -> (a, [a])
|
|
||||||
removeAt n xs = (xs !! n, take n xs ++ drop (n+1) xs)
|
|
||||||
|
|
||||||
-- Split a list into a list of lists
|
-- Split a list into a list of lists
|
||||||
-- ex. split ',' "ab,cd,ef" == ["ab","cd","ef"]
|
-- ex. split ',' "ab,cd,ef" == ["ab","cd","ef"]
|
||||||
split :: (Eq a) => a -> [a] -> [[a]]
|
split :: (Eq a) => a -> [a] -> [[a]]
|
||||||
|
@ -1,18 +1,6 @@
|
|||||||
module Alea.Random where
|
module Alea.Random where
|
||||||
|
|
||||||
import System.Random
|
import Crypto.Threefish.Random
|
||||||
import Alea.List
|
|
||||||
|
|
||||||
-- Get n random numbers from the list ys
|
|
||||||
randPick :: (Eq a, RandomGen g) => [a] -> Int -> g -> ([a], g)
|
|
||||||
randPick [] _ gen = ([], gen)
|
|
||||||
randPick _ 0 gen = ([], gen)
|
|
||||||
randPick ys n gen = (x : xs', gen'')
|
|
||||||
where
|
|
||||||
(randIndex, gen') = randomR (0, length ys - 1) gen
|
|
||||||
(x, xs) = removeAt randIndex ys
|
|
||||||
(xs', gen'') = randPick xs (n-1) gen'
|
|
||||||
|
|
||||||
-- Generate k random number in the range [0, n)
|
|
||||||
randWords :: Int -> Int -> IO [Int]
|
randWords :: Int -> Int -> IO [Int]
|
||||||
randWords n k = getStdRandom (randPick [0..n-1] k)
|
randWords n k = newSkeinGen >>= \x -> return . take k $ randomRs (0, n) x
|
||||||
|
Loading…
Reference in New Issue
Block a user