File ‹Tools/Mirabelle/mirabelle_util.ML›
signature PRNG = sig
type state
val initialize : int -> state
val next : state -> int * state
end
signature PRNG_ALGORITHMS = sig
include PRNG
val shuffle : state -> 'a list -> 'a list * state
end
functor PRNG_Algorithms(PRNG : PRNG) : PRNG_ALGORITHMS = struct
open PRNG
fun shuffle prng_state xs =
fold_map (fn x => fn prng_state =>
let
val (n, prng_state') = next prng_state
in ((n, x), prng_state') end) xs prng_state
|> apfst (sort (int_ord o apply2 fst))
|> apfst (map snd)
end
structure MLCG_PRNG : PRNG = struct
val multiplier = Word64.fromInt 6364136223846793005
val increment = Word64.fromInt 1
type state = Word64.word
val initialize = Word64.fromInt
fun next s =
let
open Word64
val s' = multiplier * s + increment
in
(toInt s', s')
end
end
structure MLCG = PRNG_Algorithms(MLCG_PRNG)