1995-10-16 05:40:46 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-10-16 05:40:46 -07:00
|
|
|
(* *)
|
|
|
|
(* Damien Doligez, projet Para, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1995-10-16 05:40:46 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
2003-06-12 04:15:26 -07:00
|
|
|
(** Pseudo-random number generators (PRNG). *)
|
|
|
|
|
|
|
|
(** {6 functions for casual users} *)
|
1995-10-16 05:40:46 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val init : int -> unit
|
2001-10-26 15:38:48 -07:00
|
|
|
(** Initialize the generator, using the argument as a seed.
|
1995-10-16 05:40:46 -07:00
|
|
|
The same seed will always yield the same sequence of numbers. *)
|
2001-10-26 15:38:48 -07:00
|
|
|
|
1995-10-16 05:40:46 -07:00
|
|
|
val full_init : int array -> unit
|
2001-12-03 14:16:03 -08:00
|
|
|
(** Same as {!Random.init} but takes more data as seed. *)
|
2001-10-26 15:38:48 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val self_init : unit -> unit
|
2001-10-26 15:38:48 -07:00
|
|
|
(** Initialize the generator with a more-or-less random seed chosen
|
2003-06-12 04:15:26 -07:00
|
|
|
in a system-dependent way. The generator is initialised with this
|
|
|
|
function at the start of the program. *)
|
1995-10-16 05:40:46 -07:00
|
|
|
|
1996-11-06 08:54:46 -08:00
|
|
|
val bits : unit -> int
|
2001-12-03 14:16:03 -08:00
|
|
|
(** Return 30 random bits in a nonnegative integer. *)
|
2001-10-26 15:38:48 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val int : int -> int
|
2001-10-26 15:38:48 -07:00
|
|
|
(** [Random.int bound] returns a random integer between 0 (inclusive)
|
1997-03-31 07:51:43 -08:00
|
|
|
and [bound] (exclusive). [bound] must be more than 0 and less
|
2001-10-29 09:58:08 -08:00
|
|
|
than 2{^30}. *)
|
2001-10-26 15:38:48 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val float : float -> float
|
2001-10-26 15:38:48 -07:00
|
|
|
(** [Random.float bound] returns a random floating-point number
|
|
|
|
between 0 (inclusive) and [bound] (exclusive). If [bound] is
|
2003-06-12 04:15:26 -07:00
|
|
|
negative, the result is negative or zero. If [bound] is 0,
|
|
|
|
the result is 0. *)
|
2000-11-20 06:20:03 -08:00
|
|
|
|
2002-02-01 04:24:44 -08:00
|
|
|
val bool : unit -> bool
|
|
|
|
(** [Random.bool ()] returns [true] or [false] with probability 0.5 each. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
type state
|
2001-10-26 15:38:48 -07:00
|
|
|
(** Values of this type are used to store the current state of the
|
|
|
|
generator. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val get_state : unit -> state
|
2003-06-12 04:15:26 -07:00
|
|
|
(** Return the current state of the generator. This is useful for
|
2001-10-26 15:38:48 -07:00
|
|
|
checkpointing computations that use the PRNG. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val set_state : state -> unit
|
2003-06-12 04:15:26 -07:00
|
|
|
(** Reset the state of the generator to some previous state returned by
|
2001-10-26 15:38:48 -07:00
|
|
|
{!Random.get_state}. *)
|
|
|
|
|
2003-06-12 04:15:26 -07:00
|
|
|
|
|
|
|
(** {6 functions for serious users} *)
|
|
|
|
|
|
|
|
(** These function manipulate the current state explicitely.
|
|
|
|
This allows you to use one or several deterministic PRNGs,
|
|
|
|
even in a multi-threaded program, without interference from
|
|
|
|
other parts of the program (for example, the Filename module
|
|
|
|
and some object-oriented primitives use the default PRNG).
|
|
|
|
*)
|
|
|
|
|
|
|
|
val s_make : int array -> state;;
|
|
|
|
(** Create a new state and initialize it with the given seed. *)
|
|
|
|
|
|
|
|
val s_copy : state -> state;;
|
|
|
|
(** Make a copy of the given state. *)
|
|
|
|
|
|
|
|
val s_bits : state -> int;;
|
|
|
|
val s_int : state -> int -> int;;
|
|
|
|
val s_float : state -> float -> float;;
|
|
|
|
val s_bool : state -> bool;;
|
|
|
|
(** These functions are the same as the above versions, except that they
|
|
|
|
use (and update) the given PRNG state instead of the default one.
|
|
|
|
*)
|