Random

unsafe class Random

The Random class provides a pseudorandom number generator.

Random is in the Prelude, meaning it is always available and does not need to be imported.

API Reference

Constructors

new()

Constructs a new Random instance.

Methods

nextInt() -> int

Returns a random integer value.


nextInt(bound: int) -> int

Returns a random integer value between 0 (inclusive) and bound (exclusive).


nextInt(origin: int, bound: int) -> int

Returns a random integer value between origin (inclusive) and bound (exclusive).


nextReal() -> real

Returns a random real value between 0.0 (inclusive) and 1.0 (exclusive).


nextReal(bound: real) -> real

Returns a random real value between 0.0 (inclusive) and bound (exclusive).


nextReal(origin: real, bound: real) -> real

Returns a random real value between origin (inclusive) and bound (exclusive).

Static Methods

threadLocal() -> Random

Returns a thread-local Random instance, re-using a previous instance if available.