CCRandomRandom Generators
include module type of struct include Stdlib.Random endtype 'a t = state -> 'aRandom generator for values of type 'a.
type 'a random_gen = 'a tval return : 'a -> 'a treturn x is the generator that always returns x. Example: let random_int = return 4 (* fair dice roll *).
Delay evaluation. Useful for side-effectful generators that need some code to run for every call. Example:
let gensym = let r = ref 0 in fun () -> incr r; !r ;;
delay (fun () ->
let name = gensym() in
small_int >>= fun i -> return (name,i)
)val choose_return : 'a list -> 'a tChoose among the list.
replicate n g makes a list of n elements which are all generated randomly using g.
sample_without_replacement n g makes a list of n elements which are all generated randomly using g with the added constraint that none of the generated random values are equal.
val pick_list : 'a list -> 'a tPick an element at random from the list.
val pick_array : 'a array -> 'a tPick an element at random from the array.
val small_int : int tA small int (100).
val int : int -> int tRandom int within the given range.
val int_range : int -> int -> int tInclusive range.
val small_float : float tA reasonably small float (100.0).
val float : float -> float tRandom float within the given range.
val float_range : float -> float -> float tInclusive range. float_range a b assumes a < b.
val split : int -> (int * int) option tSplit a positive value n into n1,n2 where n = n1 + n2.
val split_list : int -> len:int -> int list option tSplit a value n into a list of values whose sum is n and whose length is length. The list is never empty and does not contain 0.
retry g calls g until it returns some value, or until the maximum number of retries was reached. If g fails, then it counts for one iteration, and the generator retries.
try_successively l tries each generator of l, one after the other. If some generator succeeds its result is returned, else the next generator is tried.
a <?> b is a choice operator. It first tries a, and returns its result if successful. If a fails, then b is returned.
val fix :
?sub1:( 'a t -> 'a t ) list ->
?sub2:( 'a t -> 'a t -> 'a t ) list ->
?subn:(int t * ( 'a list t -> 'a t )) list ->
base:'a t ->
int t ->
'a tRecursion combinators, for building recursive values. The integer generator is used to provide fuel. The sub_ generators should use their arguments only once!
val pure : 'a -> 'a tLet operators on OCaml >= 4.08.0, nothing otherwise