From da98d65cdd776b19e8d2af8dc5519be8f40f567c Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Mon, 20 Oct 2014 16:54:23 +0200 Subject: [PATCH] Use Skein-256 as PRNG --- Alea/List.hs | 5 ----- Alea/Random.hs | 16 ++-------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Alea/List.hs b/Alea/List.hs index e71ae76..844f63f 100644 --- a/Alea/List.hs +++ b/Alea/List.hs @@ -1,10 +1,5 @@ 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 -- ex. split ',' "ab,cd,ef" == ["ab","cd","ef"] split :: (Eq a) => a -> [a] -> [[a]] diff --git a/Alea/Random.hs b/Alea/Random.hs index f173e12..e775abf 100644 --- a/Alea/Random.hs +++ b/Alea/Random.hs @@ -1,18 +1,6 @@ module Alea.Random where -import System.Random -import Alea.List +import Crypto.Threefish.Random --- 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 n k = getStdRandom (randPick [0..n-1] k) +randWords n k = newSkeinGen >>= \x -> return . take k $ randomRs (0, n) x