Commits

bergsoe  committed 1156f73

All RNG State modules are removed.

Pass an optional [rng] parameter to a function
to specify the RNG state.

  • Participants
  • Parent commits 9a9b9f6

Comments (0)

Files changed (17)

File src/PaplIndex.ml

 
   module type SETUP = sig
     type value_t
+    val rng : PaplRandom.rng_t
   end
 
   module type SETUP_MARK = sig
-    type value_t
+    include SETUP
     val get_mark : value_t -> mark_t
   end
 
           Some !min_item
       end
 
+    let int_fun = PaplRandom.int ~rng:M.rng
+
     let choose buffer =
       if A.empty buffer then None
       else
         let n = A.length buffer in
-        let i = BatRandom.int n in
+        let i = int_fun n in
           Some (A.get buffer i)
   end
 

File src/PaplIndex.mli

 
   module type SETUP = sig
     type value_t
+    val rng : PaplRandom.rng_t
   end
 
   module type SETUP_MARK = sig
-    type value_t
+    include SETUP
     val get_mark : value_t -> mark_t
   end
 

File src/PaplRandom.ml

+type rng_t = BatRandom.State.t option
 
-let random_enum clone next =
-  let count () = raise BatEnum.Infinite_enum in
-  let clone () = clone (BatRandom.get_state ()) in
-    BatEnum.make next count clone
-
-let enum_bits () =
-  let next = BatRandom.bits in
-  let clone state = BatRandom.State.enum_bits state () in
-    random_enum clone next
-
-let enum_int bound =
-  let next () = BatRandom.int bound in
-  let clone state = BatRandom.State.enum_int state bound in
-    random_enum clone next
-
-let enum_int32 bound =
-  let next () = BatRandom.int32 bound in
-  let clone state = BatRandom.State.enum_int32 state bound in
-    random_enum clone next
-
-let enum_int64 bound =
-  let next () = BatRandom.int64 bound in
-  let clone state = BatRandom.State.enum_int64 state bound in
-    random_enum clone next
-
-let enum_float bound =
-  let next () = BatRandom.float bound in
-  let clone state = BatRandom.State.enum_float state bound in
-    random_enum clone next
-
-let enum_nativeint bound =
-  let next () = BatRandom.nativeint bound in
-  let clone state = BatRandom.State.enum_nativeint state bound in
-    random_enum clone next
-
-let enum_bool () =
-  let next = BatRandom.bool in
-  let clone state = BatRandom.State.enum_bool state () in
-    random_enum clone next
-
-let enum_char () =
-  let next = BatRandom.char in
-  let clone state = BatRandom.State.enum_char state () in
-    random_enum clone next
+module Helper = struct
+  let random_enum clone next =
+    let count () = raise BatEnum.Infinite_enum in
+    let clone () = clone (BatRandom.get_state ()) in
+      BatEnum.make next count clone
+
+  let enum_bits () =
+    let next = BatRandom.bits in
+    let clone state = BatRandom.State.enum_bits state () in
+      random_enum clone next
+
+  let enum_int bound =
+    let next () = BatRandom.int bound in
+    let clone state = BatRandom.State.enum_int state bound in
+      random_enum clone next
+
+  let enum_int32 bound =
+    let next () = BatRandom.int32 bound in
+    let clone state = BatRandom.State.enum_int32 state bound in
+      random_enum clone next
+
+  let enum_int64 bound =
+    let next () = BatRandom.int64 bound in
+    let clone state = BatRandom.State.enum_int64 state bound in
+      random_enum clone next
+
+  let enum_float bound =
+    let next () = BatRandom.float bound in
+    let clone state = BatRandom.State.enum_float state bound in
+      random_enum clone next
+
+  let enum_nativeint bound =
+    let next () = BatRandom.nativeint bound in
+    let clone state = BatRandom.State.enum_nativeint state bound in
+      random_enum clone next
+
+  let enum_bool () =
+    let next = BatRandom.bool in
+    let clone state = BatRandom.State.enum_bool state () in
+      random_enum clone next
+
+  let enum_char () =
+    let next = BatRandom.char in
+    let clone state = BatRandom.State.enum_char state () in
+      random_enum clone next
+end
+
+let enum_by ?rng:(rng = None) default_fun state_fun =
+  match rng with
+      None -> default_fun
+    | Some state -> fun arg -> state_fun state arg
+
+let enum_bits ?rng =
+  enum_by ?rng Helper.enum_bits BatRandom.State.enum_bits
+
+let enum_int ?rng =
+  enum_by ?rng Helper.enum_int BatRandom.State.enum_int
+
+let enum_int32 ?rng =
+  enum_by ?rng Helper.enum_int32 BatRandom.State.enum_int32
+
+let enum_int64 ?rng =
+  enum_by ?rng Helper.enum_int64 BatRandom.State.enum_int64
+
+let enum_float ?rng =
+  enum_by ?rng Helper.enum_float BatRandom.State.enum_float
+
+let enum_nativeint ?rng =
+  enum_by ?rng Helper.enum_nativeint BatRandom.State.enum_nativeint
+
+let enum_bool ?rng =
+  enum_by ?rng Helper.enum_bool BatRandom.State.enum_bool
+
+let enum_char ?rng =
+  enum_by ?rng Helper.enum_char BatRandom.State.enum_char
+
+let get_by ?rng:(rng = None) default_fun state_fun =
+  match rng with
+      None -> default_fun
+    | Some state -> fun arg -> state_fun state arg
+
+let int ?rng = get_by ?rng BatRandom.int BatRandom.State.int
+let int32 ?rng = get_by ?rng BatRandom.int32 BatRandom.State.int32
+let nativeint ?rng = get_by ?rng BatRandom.nativeint BatRandom.State.nativeint
+let int64 ?rng = get_by ?rng BatRandom.int64 BatRandom.State.int64
+let float ?rng = get_by ?rng BatRandom.float BatRandom.State.float
+
+let bits ?rng:(rng = None) =
+  match rng with
+      None -> BatRandom.bits
+    | Some state -> fun () -> BatRandom.State.bits state
+
+let bool ?rng:(rng = None) =
+  match rng with
+      None -> BatRandom.bool
+    | Some state -> fun () -> BatRandom.State.bool state

File src/PaplRandom.mli

 
-val enum_bits  : unit    -> int BatEnum.t
+type rng_t = BatRandom.State.t option
 
-val enum_int   : int     -> int BatEnum.t
+val enum_bits : ?rng:rng_t -> unit -> int BatEnum.t
 
-val enum_bool  : unit    -> bool BatEnum.t
+val enum_int : ?rng:rng_t -> int -> int BatEnum.t
 
-val enum_float : float   -> float BatEnum.t
+val enum_bool : ?rng:rng_t -> unit -> bool BatEnum.t
 
-val enum_int32 : Int32.t -> Int32.t BatEnum.t
+val enum_float : ?rng:rng_t -> float -> float BatEnum.t
 
-val enum_int64 : Int64.t -> Int64.t BatEnum.t
+val enum_int32 : ?rng:rng_t -> Int32.t -> Int32.t BatEnum.t
 
-val enum_nativeint : Nativeint.t -> Nativeint.t BatEnum.t
+val enum_int64 : ?rng:rng_t -> Int64.t -> Int64.t BatEnum.t
 
-val enum_char : unit -> char BatEnum.t
+val enum_nativeint : ?rng:rng_t -> Nativeint.t -> Nativeint.t BatEnum.t
+
+val enum_char : ?rng:rng_t -> unit -> char BatEnum.t
+
+val bits : ?rng:rng_t -> unit -> int
+
+val int : ?rng:rng_t -> int -> int
+
+val int32 : ?rng:rng_t -> Int32.t -> Int32.t
+
+val nativeint : ?rng:rng_t -> Nativeint.t -> Nativeint.t
+
+val int64 : ?rng:rng_t -> Int64.t -> Int64.t
+
+val float : ?rng:rng_t -> float -> float
+
+val bool : ?rng:rng_t -> unit -> bool

File src/PaplSBL.ml

         let connect_dist = lift_dist S.connect_dist
         let connect_constr = lift_constr S.connect_constr
         let get_mark = get_mark
+        let rng = S.rng
       end
       module Index = PaplTreeIndex.BruteForce.UnbiasedEST.MakeDLT
         (LiftIndexSetup)
         let expand_dist = lift_dist S.expand_dist
         let expand_constr = lift_constr S.expand_constr
         let get_mark = get_mark
+        let rng = S.rng
       end
       module Index = PaplTreeIndex.BruteForce.RRT.MakeDLT(LiftIndexSetup)
 

File src/PaplSBLExpandSampler.ml

+type rng_t = PaplRandom.rng_t
 
 let random_range_helper float_fun = ();
   fun (a, b) -> a +. float_fun (b -. a)
           in
             BatEnum.from_while next
 
-    let uniform_within_boxes outer inner_boxes =
+    let uniform_within_boxes ?rng outer inner_boxes =
       uniform_within_boxes_helper
-        BatRandom.float outer inner_boxes
-
-    module State = struct
-      let uniform_within_boxes state outer inner_boxes =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          outer
-          inner_boxes
-    end
+        (PaplRandom.float ?rng) outer inner_boxes
   end
 
   module Q = struct
             end
           in BatEnum.from_while next
 
-    let uniform_within_boxes outer inner_boxes =
+    let uniform_within_boxes ?rng outer inner_boxes =
       uniform_within_boxes_helper
-        BatRandom.float outer inner_boxes
-
-    module State = struct
-      let uniform_within_boxes state outer inner_boxes =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          outer
-          inner_boxes
-    end
+        (PaplRandom.float ?rng) outer inner_boxes
   end
 
   module V2D = struct
           in
             BatEnum.from_while next
 
-    let uniform_within_boxes outer inner_boxes =
+    let uniform_within_boxes ?rng outer inner_boxes =
       uniform_within_boxes_helper
-        BatRandom.float outer inner_boxes
-
-    module State = struct
-      let uniform_within_boxes state outer inner_boxes =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          outer
-          inner_boxes
-    end
+        (PaplRandom.float ?rng) outer inner_boxes
   end
 
   module I2D = struct
       in
         fun q -> BatEnum.map to_int (make (to_float q))
 
-    let uniform_within_boxes outer inner_boxes =
+    let uniform_within_boxes ?rng outer inner_boxes =
       uniform_within_boxes_helper
-        BatRandom.float outer inner_boxes
-
-    module State = struct
-      let uniform_within_boxes state outer inner_boxes =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          outer
-          inner_boxes
-    end
+        (PaplRandom.float ?rng) outer inner_boxes
   end
 
   module SO2 = struct
           in
             BatEnum.from_while next
 
-    let uniform_within_boxes accept inner_boxes =
+    let uniform_within_boxes ?rng accept inner_boxes =
       uniform_within_boxes_helper
-        BatRandom.float accept inner_boxes
-
-    module State = struct
-      let uniform_within_boxes state accept inner_boxes =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          accept
-          inner_boxes
-    end
+        (PaplRandom.float ?rng) accept inner_boxes
   end
 
   module SE2 = struct
       in make_sampler
 
     let uniform_within_boxes
+        ?rng
         outer_pos_box inner_pos_boxes
         accept_angle inner_angle_boxes
         =
       uniform_within_boxes_helper
-        BatRandom.float
+        (PaplRandom.float ?rng)
         outer_pos_box inner_pos_boxes
         accept_angle inner_angle_boxes
-
-    module State = struct
-      let uniform_within_boxes
-          state
-          outer_pos_box inner_pos_boxes
-          accept_angle inner_angle_boxes
-          =
-        uniform_within_boxes_helper
-          (BatRandom.State.float state)
-          outer_pos_box inner_pos_boxes
-          accept_angle inner_angle_boxes
-    end
   end
 
   module Time = struct
     random_subdivide_n_helper
       (fun s -> s) n interpolate dist range
 
-  let random_subdivide_n n interpolate dist range =
-    random_subdivide_n_helper BatRandom.float n interpolate dist range
+  let random_subdivide_n ?rng n interpolate dist range =
+    random_subdivide_n_helper
+      (PaplRandom.float ?rng) n interpolate dist range
 
   let fixed_steps interpolate dist steps =
     fun qa qb ->
                interpolate qa qb s)
             sampler
 
-  let uniform_within_boxes interpolate boxes =
+  let uniform_within_boxes ?rng interpolate boxes =
     uniform_within_boxes_helper
-      BatRandom.float
+      (PaplRandom.float ?rng)
       interpolate
       boxes
 
       BatEnum.concat
         (BatList.enum
            (BatList.map (fun e -> e qa qb) es))
-
-  module State = struct
-    let random_subdivide_n state n interpolate dist range =
-      random_subdivide_n_helper
-        (BatRandom.State.float state)
-        n interpolate dist range
-
-    let uniform_within_boxes state interpolate boxes =
-      uniform_within_boxes_helper
-        (BatRandom.State.float state)
-        interpolate
-        boxes
-  end
 end

File src/PaplSBLExpandSampler.mli

     vicinity of some configuration.
 *)
 
+type rng_t = PaplRandom.rng_t
+
 module EST : sig
   type 'a expand_sampler_t = 'a PaplSBL.EST.expand_sampler_t
 
     val standard_boxes_by_offset : int -> t -> box_t array
 
     val uniform_within_boxes :
-      box_t -> box_t array -> t expand_sampler_t
-
-    module State : sig
-      val uniform_within_boxes :
-        BatRandom.State.t ->
-        box_t -> box_t array -> t expand_sampler_t
-    end
+      ?rng:rng_t -> box_t -> box_t array -> t expand_sampler_t
   end
 
   module Q : sig
     val standard_boxes_by_offset : int -> t -> box_t array
 
     val uniform_within_boxes :
-      box_t -> box_t array -> t expand_sampler_t
-
-    module State : sig
-      val uniform_within_boxes :
-        BatRandom.State.t ->
-        box_t -> box_t array -> t expand_sampler_t
-    end
+      ?rng:rng_t -> box_t -> box_t array -> t expand_sampler_t
   end
 
   module V2D : sig
       *)
 
     val uniform_within_boxes :
-      box_t -> box_t array -> t expand_sampler_t
-
-    module State : sig
-      val uniform_within_boxes :
-        BatRandom.State.t ->
-        box_t -> box_t array -> t expand_sampler_t
-    end
+      ?rng:rng_t -> box_t -> box_t array -> t expand_sampler_t
   end
 
   module I2D : sig
     val standard_boxes_by_offset : int -> t -> box_t array
 
     val uniform_within_boxes :
-      box_t -> box_t array -> t expand_sampler_t
-
-    module State : sig
-      val uniform_within_boxes :
-        BatRandom.State.t ->
-        box_t -> box_t array -> t expand_sampler_t
-    end
+      ?rng:rng_t -> box_t -> box_t array -> t expand_sampler_t
   end
 
   module SO2 : sig
     val standard_boxes_by_offset : int -> float -> box_t array
 
     val uniform_within_boxes :
+      ?rng:rng_t ->
       (float -> 'a option) ->
       box_t array ->
       t -> 'a BatEnum.t
-
-    module State : sig
-      val uniform_within_boxes :
-        BatRandom.State.t ->
-        (float -> 'a option) ->
-        box_t array ->
-        t -> 'a BatEnum.t
-    end
   end
 
   module SE2 : sig
     type rot_box_t = float * float
 
     val uniform_within_boxes :
-      pos_box_t -> pos_box_t array ->
-      (float -> PaplTransform.SO2.t option) -> rot_box_t array ->
+      ?rng:rng_t ->
+      pos_box_t ->
+      pos_box_t array ->
+      (float -> PaplTransform.SO2.t option) ->
+      rot_box_t array ->
       t expand_sampler_t
+  (** [uniform_within_boxes outer_pos_box inner_pos_boxes accept_angle
+      inner_angle_boxes]
+  *)
   end
 
   module Time : sig
     'a expand_sampler_t
 
   val random_subdivide_n :
+    ?rng:rng_t ->
     int -> (* n : if negative then continue to [lower]. *)
     'a PaplInterpolate.t ->
     'a PaplMetric.t ->
     'a expand_sampler_t
 
   val uniform_within_boxes :
+    ?rng:rng_t ->
     'a PaplInterpolate.t -> box_t array -> 'a expand_sampler_t
 
   val concat :
     'a expand_sampler_t list ->
     'a expand_sampler_t
-
-  module State : sig
-    val random_subdivide_n :
-      BatRandom.State.t ->
-      int ->
-      'a PaplInterpolate.t ->
-      'a PaplMetric.t ->
-      (float * float) ->
-      'a expand_sampler_t
-
-    val uniform_within_boxes :
-      BatRandom.State.t ->
-      'a PaplInterpolate.t ->
-      box_t array ->
-      'a expand_sampler_t
-  end
 end

File src/PaplSampler.ml

+type rng_t = PaplRandom.rng_t
+
 type 'a pair_t = 'a * 'a
 
 open BatStd
     else
       BatEnum.from_while make
 
-let distribute_by_weight pairs =
-  distribute_by_weight_helper PaplRandom.enum_float pairs
+let distribute_by_weight ?rng pairs =
+  distribute_by_weight_helper (PaplRandom.enum_float ?rng) pairs
 
 let uniform_helper enum_fun (a, b) =
   if a > b then BatEnum.empty ()
     raise (RangeError ("a > b", (a, b)))
   else a +. float_fun (b -. a)
 
-let get_uniform range =
-  get_uniform_helper BatRandom.float range
+let get_uniform ?rng range =
+  get_uniform_helper (PaplRandom.float ?rng) range
 
-let uniform = uniform_helper PaplRandom.enum_float
+let uniform ?rng range = uniform_helper (PaplRandom.enum_float ?rng) range
 
 let uniform_int_helper enum_fun (a, b) =
   if a >= b then BatEnum.empty ()
   else if a = b - 1 then BatEnum.repeat a
   else BatEnum.map ((+) a) (enum_fun (b - a))
 
-let uniform_int = uniform_int_helper PaplRandom.enum_int
+let uniform_int ?rng range =
+  uniform_int_helper (PaplRandom.enum_int ?rng) range
 
 (* Given a function that returns pairs (x, y), construct a caching function that
    returns first x and then y.
 
 let gaussian_helper = box_muller_gaussian
 
-let gaussian () = gaussian_helper BatRandom.float
-
-module State = struct
-  let distribute_by_weight state pairs =
-    distribute_by_weight_helper (BatRandom.State.enum_float state) pairs
-
-  let uniform state =
-    uniform_helper (BatRandom.State.enum_float state)
-
-  let get_uniform state =
-    get_uniform_helper (BatRandom.State.float state)
-
-  let uniform_int state =
-    uniform_int_helper (BatRandom.State.enum_int state)
-
-  let gaussian state =
-    gaussian_helper (BatRandom.State.float state)
-end
+let gaussian ?rng () =
+  gaussian_helper (PaplRandom.float ?rng)
 
 let mean_and_variance stream =
   let xs = BatList.of_enum stream in

File src/PaplSampler.mli

     functions for constructing enumerations for different types of sequence
     data. For example:
 
-    - {! BatRandom} constructs enumerations of random numbers.
+    - {! PaplRandom} constructs enumerations of random numbers.
 
     - {! BatList} converts between lists and enumerations.
 
 
 (** {2 Random sampling} *)
 
-val distribute_by_weight : (float * 'a) BatEnum.t -> 'a t
+type rng_t = PaplRandom.rng_t
+
+val distribute_by_weight :
+  ?rng:rng_t ->
+  (float * 'a) BatEnum.t ->
+  'a t
 (** Sampling of elements distributed by weight.
 
     The sampler [s = distribute_by_weight pairs] returns values [x] from an
     Weights must be non-negative.
 *)
 
-val uniform : range_t -> float t
+val uniform : ?rng:rng_t -> range_t -> float t
 (** Random uniform sampling of a range.
 
     The sampler [random_uniform range] uniformly samples the range [range].
     If the range is empty then the sampler is empty.
 *)
 
-val get_uniform : range_t -> float
+val get_uniform : ?rng:rng_t -> range_t -> float
 (** A single value sampled uniformly at random from a range.
 
     If the range is empty then an exception is raised.
 *)
 
-val uniform_int : int_range_t -> int t
+val uniform_int : ?rng:rng_t -> int_range_t -> int t
 (** Random sampling of ranges.
 
     The sampler [s = uniform_int range] returns integers sampled uniformly at
     If the range is empty then [s] is empty.
 *)
 
-val gaussian : unit -> float t
-(** Normal distributed numbers with mean 0 and variance 1.
-*)
-
-(** Random sampling for a RNG state. *)
-module State : sig
-
-  val distribute_by_weight :
-    BatRandom.State.t -> (float * 'a) t -> 'a t
-(** Sampling of elements distributed by weight.
-
-    The sampler [s = distribute_by_weight state pairs] returns values [x] from
-    an enumeration of pairs [(w, x)]. A value [x] is sampled with a probability
-    proportional to its weight relative to the total weight of all pairs.
-    Weights must be non-negative.
-*)
-
-  val uniform : BatRandom.State.t -> range_t -> float t
-(** Random uniform sampling of a range.
-
-    The sampler [random_uniform state range] uniformly samples the range
-    [range].
-
-    If the range is empty then the sampler is empty.
-*)
-
-  val get_uniform : BatRandom.State.t -> range_t -> float
-(** A single value sampled uniformly at random from a range.
-
-    If the range is empty then an exception is raised.
-*)
-
-  val uniform_int : BatRandom.State.t -> int_range_t -> int t
-(** Random sampling of ranges.
-
-    The sampler [s = uniform_int state range] returns integers sampled uniformly
-    at random from [range].
-
-    If the range is empty then [s] is empty.
-*)
-
-  val gaussian : BatRandom.State.t -> float t
+val gaussian : ?rng:rng_t -> unit -> float t
 (** Normal distributed numbers with mean 0 and variance 1.
 *)
-end
 
 (** {2 Utilities} *)
 

File src/PaplTime.ml

 type 'a pair_t = 'a * 'a
+type rng_t = PaplRandom.rng_t
 
 type 'a t = {
   time : float;
 
   let to_option s = BatEnum.map (fun x -> Some x) s
 
-  let uniform range sq = make (PaplSampler.uniform range) sq
+  let uniform ?rng range sq = make (PaplSampler.uniform ?rng range) sq
 
-  let get_uniform sq range =
+  let get_uniform ?rng range sq =
     match BatEnum.get sq with
         None -> None
       | Some q ->
-          let t = PaplSampler.get_uniform range in
+          let t = PaplSampler.get_uniform ?rng range in
             Some (time_space_make t q)
 
   let fold_time op init qts =

File src/PaplTime.mli

 *)
 
 type 'a pair_t = 'a * 'a
+type rng_t = PaplRandom.rng_t
 
 (** {2 Types} *)
 
     becomes empty, then so does [s].
 *)
 
-  val uniform : range_t -> 'a PaplSampler.t -> ('a t) PaplSampler.t
+  val uniform :
+    ?rng:rng_t -> range_t -> 'a PaplSampler.t -> ('a t) PaplSampler.t
 (** Uniform sampling of a time range.
 
     The sampler [s = uniform range sq] returns time configurations [(t, q)]
     [s] is empty if the range is empty or if [sq] becomes empty.
 *)
 
-  val get_uniform : 'a PaplSampler.t -> range_t -> 'a t option
+  val get_uniform : ?rng:rng_t -> range_t -> 'a PaplSampler.t -> 'a t option
 end
 
 (** {2 Trajectories} *)

File src/PaplTransform.ml

 
 (* ---------------------------------------------------------------------- *)
 
+type rng_t = PaplRandom.rng_t
+
 module SO2 = struct
   module V2D = PaplVector.V2D
 
   let complex a = { Complex.re = cos a; im = sin a }
 
   module Sampler = struct
-    let uniform range = BatEnum.map rotate (PaplSampler.uniform range)
+    let uniform ?rng range =
+      BatEnum.map rotate (PaplSampler.uniform ?rng range)
 
-    let uniform_all () = uniform (-. pi, pi)
+    let uniform_all ?rng () = uniform ?rng (-. pi, pi)
   end
 end
 
 
     let make sp so = PaplSampler.product2 sp so
 
-    let uniform box range =
+    let uniform ?rng box range =
       make
-        (PaplVector.V2D.Sampler.uniform box)
-        (SO2.Sampler.uniform range)
+        (PaplVector.V2D.Sampler.uniform ?rng box)
+        (SO2.Sampler.uniform ?rng range)
 
-    let uniform_all box =
+    let uniform_all ?rng box =
       make
-        (PaplVector.V2D.Sampler.uniform box)
-        (SO2.Sampler.uniform_all ())
+        (PaplVector.V2D.Sampler.uniform ?rng box)
+        (SO2.Sampler.uniform_all ?rng ())
   end
 end
 

File src/PaplTransform.mli

 (** Rigid body transformations
 *)
 
+type rng_t = PaplRandom.rng_t
+
 (** 2D rotations *)
 module SO2 : sig
   include PaplSpatialGroup.S with type vec = PaplVector.V2D.t
   val in_range : float -> (float * float) -> bool
 
   module Sampler : sig
-    val uniform : (float * float) -> t PaplSampler.t
+    val uniform : ?rng:rng_t -> (float * float) -> t PaplSampler.t
       (** Uniform sampling over a range of angles.
 
           [uniform range] uniformly samples values [a] from [range] and returns
           values [rotate a].
       *)
 
-    val uniform_all : unit -> t PaplSampler.t
+    val uniform_all : ?rng:rng_t -> unit -> t PaplSampler.t
       (** Uniform sampling of all possible 2D rotations.
       *)
   end
 
     val make : vec PaplSampler.t -> SO2.t PaplSampler.t -> t PaplSampler.t
 
-    val uniform : box_t -> (float * float) -> t PaplSampler.t
+    val uniform : ?rng:rng_t -> box_t -> (float * float) -> t PaplSampler.t
 
-    val uniform_all : box_t -> t PaplSampler.t
+    val uniform_all : ?rng:rng_t -> box_t -> t PaplSampler.t
   end
 
   module PlannerConstraint : sig

File src/PaplTreeIndex.ml

     type q_t
     val connect_dist : q_t PaplMetric.option_t
     val connect_constr : q_t PaplEdgeConstraint.t option
+    val rng : PaplRandom.rng_t
   end
 
   module type SETUP_DLT = sig
     type q_t = M.q_t
     type node_t = q_t Tree.node
 
-    module IndexSetup = struct type value_t = node_t end
+    module IndexSetup = struct
+      type value_t = node_t
+      let rng = M.rng
+    end
     module Index = PaplIndex.BruteForce.Make(IndexSetup)
 
     type t = Index.t
     module IndexSetup = struct
       type value_t = node_t
       let get_mark = get_mark
+      let rng = M.rng
     end
     module Index = PaplIndex.BruteForce.MakeMark(IndexSetup)
 

File src/PaplTreeIndex.mli

     type q_t
     val connect_dist : q_t PaplMetric.option_t
     val connect_constr : q_t PaplEdgeConstraint.t option
+    val rng : PaplRandom.rng_t
   end
 
   module type SETUP_DLT = sig

File src/PaplVector.ml

+type rng_t = PaplRandom.rng_t
 type 'a pair_t = 'a * 'a
 
 module type BASE = sig
   type t
   type box_t = t * t
 
-  val uniform : box_t -> t
-  module State : sig
-    val uniform : BatRandom.State.t -> box_t -> t
-  end
+  val uniform : ?rng:rng_t -> box_t -> t
 end
 
 module type SAMPLER = sig
   type t
   type box_t = t * t
 
-  val uniform : box_t -> t PaplSampler.t
-  module State : sig
-    val uniform : BatRandom.State.t -> box_t -> t PaplSampler.t
-  end
+  val uniform : ?rng:rng_t -> box_t -> t PaplSampler.t
 end
 
 module type BASE_OP = sig
     let d = b -: a
     in random_offset float_fun a d
 
-  let uniform = uniform_helper BatRandom.float
-
-  module State = struct
-    let uniform state = uniform_helper (BatRandom.State.float state)
-  end
+  let uniform ?rng box = uniform_helper (PaplRandom.float ?rng) box
 end
 
 module MakeSampler (V : BASE) (M : BASE_OP with type t = V.t) = struct
     let next () = Some (random_offset float_fun a d)
     in BatEnum.from_while next
 
-  let uniform = uniform_helper BatRandom.float
-
-  module State = struct
-    let uniform state = uniform_helper (BatRandom.State.float state)
-  end
+  let uniform ?rng box = uniform_helper (PaplRandom.float ?rng) box
 end
 
 (* Vector accessors *)

File src/PaplVector.mli

 (** Vectors
 *)
 
+type rng_t = PaplRandom.rng_t
 type 'a pair_t = 'a * 'a
 
 (** Common vector interface *)
   type t
   type box_t = t * t
 
-  val uniform : box_t -> t
+  val uniform : ?rng:rng_t -> box_t -> t
 (** A configuration sampled uniformly at random from a box. *)
-
-  module State : sig
-    val uniform : BatRandom.State.t -> box_t -> t
-(** A configuration sampled uniformly at random from a box. *)
-  end
 end
 
 (** {2 Samplers} *)
   type t
   type box_t = t * t
 
-  val uniform : box_t -> t PaplSampler.t
-(** Uniform sampling of a configuration space box. *)
-
-(** Sampling for a RNG state. *)
-  module State : sig
-    val uniform : BatRandom.State.t -> box_t -> t PaplSampler.t
+  val uniform : ?rng:rng_t -> box_t -> t PaplSampler.t
 (** Uniform sampling of a configuration space box. *)
-  end
 end
 
 (** {2 All} *)