Module JavaRandom

module JavaRandom: sig .. end
Pseudorandom number generators.


Instance creation

 
type t = java'util'Random java_instance
The type of pseudorandom number generators.
 
val make : unit -> t
Returns a new java.util.Random instance.
 
val make_of_seed : java_long -> t
Returns a new java.util.Random instance, built using the passed seed.
 
val make_secure : ?algorithm:JavaString.t -> ?provider:JavaString.t -> unit -> t
Returns a new java.security.SecureRandom instance, using algorithm (if different from null) to generate the numbers as implemented by provider (if different from null).

Both algorithm and provider default to null.
Raises Java_exception if the specified algorithm or provider cannot be found
 
val current_thread_local : unit -> t
Returns the instance of java.util.concurrent.ThreadLocalRandom for the current thread.
 

Numbers generation

 
val next_boolean : t -> java_boolean
Generates a new pseudorandom boolean; see nextBoolean(...).
 
val next_bytes : t -> java_byte java_byte_array -> unit
Generates new pseudorandom bytes; see nextBytes(...).
 
val next_double : t -> java_double
Generates a new pseudorandom double; see nextDouble(...).
 
val next_float : t -> java_float
Generates a new pseudorandom float; see nextFloat(...).
 
val next_gaussian : t -> java_double
Generates a new pseudorandom double that is Gaussian distributed; see nextGaussian(...).
 
val next_int : t -> java_int
Generates a new pseudorandom integer; see nextInt(...).
 
val next_int_bound : t -> java_int -> java_int
Generates a new pseudorandom integer between 0 (inclusive) and the passed value (exclusive); see nextInt(...).
 
val next_long : t -> java_long
Generates a new pseudorandom long; see nextLong(...).
 

Generator seed

 
val set_seed : t -> java_long -> unit
set_seed random seed Sets the seed of the random generator to seed; see setSeed(...).
 

Null value

 
val null : t
The null value.
 
val is_null : t -> bool
is_null obj returns true iff obj is equal to null.
 
val is_not_null : t -> bool
is_not_null obj returns false iff obj is equal to null.
 

Miscellaneous

 
val wrap : t -> t option
wrap obj wraps the reference obj into an option type:
  • Some x if obj is not null;
  • None if obj is null.

 
val unwrap : t option -> t
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.