Patch subject is complete summary.

2 files changed, 8 insertions(+), 7 deletions(-)
uuid/uuid.ml  |   14 +++++++-------
uuid/uuid.mli |    1 +


# HG changeset patch
# User Magnus Therning <[email protected]>
# Date 1280417699 -3600
# Node ID caffaeb28aaf0e2a41bc54b58be299ed8ba64d56
# Parent  45735e09188a2445ff0e8c9fd5dbf339969a8c90
Add a function to get guaranteed high-quality uuids.

diff -r 45735e09188a -r caffaeb28aaf uuid/uuid.ml
--- a/uuid/uuid.ml	Thu Jul 29 15:54:02 2010 +0100
+++ b/uuid/uuid.ml	Thu Jul 29 16:34:59 2010 +0100
@@ -30,12 +30,11 @@
 
 let cookie_of_string s = s
 
-(* FIXME: using /dev/random is too slow but using /dev/urandom is too
-    deterministic. *)
-let dev_random = "/dev/urandom"
+let dev_random = "/dev/random"
+let dev_urandom = "/dev/urandom"
 
-let read_random n = 
-  let ic = open_in_bin dev_random in
+let read_array dev n = 
+  let ic = open_in_bin dev in
   try
     let result = Array.init n (fun _ -> input_byte ic) in
     close_in ic;
@@ -50,10 +49,11 @@
     uuid.(6) uuid.(7) uuid.(8) uuid.(9) uuid.(10) uuid.(11)
     uuid.(12) uuid.(13) uuid.(14) uuid.(15)
 
-let make_uuid() = uuid_of_int_array (read_random 16)
+let make_uuid() = uuid_of_int_array (read_array dev_urandom 16)
+let make_uuid_random () = uuid_of_int_array (read_array dev_random 16)
 
 let make_cookie() =
-  let bytes = Array.to_list (read_random 64) in
+  let bytes = Array.to_list (read_array dev_urandom 64) in
   String.concat "" (List.map (Printf.sprintf "%1x") bytes)
 
 let int_array_of_uuid s =
diff -r 45735e09188a -r caffaeb28aaf uuid/uuid.mli
--- a/uuid/uuid.mli	Thu Jul 29 15:54:02 2010 +0100
+++ b/uuid/uuid.mli	Thu Jul 29 16:34:59 2010 +0100
@@ -27,6 +27,7 @@
 
 (** Create a fresh UUID *)
 val make_uuid : unit -> 'a t
+val make_uuid_random : unit -> 'a t
 
 (** Create a type-safe UUID. *)
 val of_string : string -> 'a t
_______________________________________________
xen-api mailing list
[email protected]
http://lists.xensource.com/mailman/listinfo/xen-api

Reply via email to