summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>1999-07-22 13:00:59 +0000
committerDamien Doligez <damien.doligez-inria.fr>1999-07-22 13:00:59 +0000
commit8a8a0c17ae03cf025411f33f40ac3bf6a588b1c3 (patch)
treecb247de6d002e787ff2d0b8506c2ef31b11a5a90
parent8d6245cdbedf4528cab4ff7c46b3ab37c11b0b4a (diff)
ajout de Random.self_init et Sys.date. Attention bootstrap difficile.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2384 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--stdlib/random.ml3
-rw-r--r--stdlib/random.mli3
-rw-r--r--stdlib/sys.ml1
-rw-r--r--stdlib/sys.mli3
4 files changed, 10 insertions, 0 deletions
diff --git a/stdlib/random.ml b/stdlib/random.ml
index 33851b9b1..07b3d67bc 100644
--- a/stdlib/random.ml
+++ b/stdlib/random.ml
@@ -85,6 +85,9 @@ let full_init seed =
(Array.unsafe_get state j + Array.unsafe_get seed i)
done
+(* Low-entropy system-dependent initialisation. *)
+let self_init () = init (int_of_float (Sys.date () -. 2e9));;
+
(********************
(* Test functions. Not included in the library.
diff --git a/stdlib/random.mli b/stdlib/random.mli
index ea53316f8..f262b4c75 100644
--- a/stdlib/random.mli
+++ b/stdlib/random.mli
@@ -18,6 +18,9 @@ val init : int -> unit
The same seed will always yield the same sequence of numbers. *)
val full_init : int array -> unit
(* Same as [init] but takes more data as seed. *)
+val self_init : unit -> unit
+ (* Initialize the generator with a more-or-less random seed chosen
+ in a system-dependent way. *)
val bits : unit -> int
(* Return 30 random bits in a nonnegative integer. *)
diff --git a/stdlib/sys.ml b/stdlib/sys.ml
index 4bfc0c236..cbea8fb23 100644
--- a/stdlib/sys.ml
+++ b/stdlib/sys.ml
@@ -27,6 +27,7 @@ external rename : string -> string -> unit = "sys_rename"
external getenv: string -> string = "sys_getenv"
external command: string -> int = "sys_system_command"
external time: unit -> float = "sys_time"
+external date: unit -> float = "sys_date"
external chdir: string -> unit = "sys_chdir"
external getcwd: unit -> string = "sys_getcwd"
diff --git a/stdlib/sys.mli b/stdlib/sys.mli
index 009f70a8d..c7efa8c0d 100644
--- a/stdlib/sys.mli
+++ b/stdlib/sys.mli
@@ -33,6 +33,9 @@ external command: string -> int = "sys_system_command"
external time: unit -> float = "sys_time"
(* Return the processor time, in seconds, used by the program
since the beginning of execution. *)
+external date: unit -> float = "sys_date"
+ (* Return the current calendar time, or -1.0 if the time is not
+ available. The unit and origin are unspecified. *)
external chdir: string -> unit = "sys_chdir"
(* Change the current working directory of the process. *)
external getcwd: unit -> string = "sys_getcwd"