Commits

Yit Phang Khoo committed 7489a53

Add Types.Seeds for random number streams.

Comments (0)

Files changed (1)

Source/Adapton/Types.ml

-(** Convenience modules for built-in types. *)
+(** Convenience modules for built-in and other useful types. *)
 
 module Int = struct
     type t = int
     let hash seed ( a, b, c, d ) = D.hash (C.hash (B.hash (A.hash seed a) b) c) d
     let equal ( a, b, c, d as x ) ( a', b', c', d' as x' ) = x == x' || A.equal a a' && B.equal b b' && C.equal c c' && D.equal d d'
 end
+
+(** Random number stream. *)
+module Seeds = struct
+    type t = Seeds of int * t Lazy.t
+    let make ?seeds:seeds_opt () =
+        let rng = match seeds_opt with
+            | Some seeds -> Random.State.make seeds
+            | None -> Random.State.make_self_init ()
+        in
+        let rec seeds () = Seeds ( Random.State.bits rng, Lazy.from_fun seeds ) in
+        seeds ()
+    let pop ( Seeds ( s, lazy seeds ) ) = ( s, seeds )
+    let hash seed ( Seeds ( s, _ ) ) = Hashtbl.seeded_hash seed s
+    let equal = (==)
+end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.