Skip to content

Randomness

[Source]

Source of randomness, providing methods for generating uniformly distributed values of the primitive numeric types.

The integer methods (u8 through isize) generate values in the closed interval [min, max]. Both bounds are included, so every value of the type can be produced.

The floating-point methods (f32 and f64) scale a value from the underlying generator's real() (uniformly distributed in [0, 1)) onto the requested range. min is always reachable and results are never below min, but max is only an approximate upper bound: floating-point rounding means max may or may not be produced, and an f32 result can land marginally above max. Do not rely on max being included or excluded.

class ref Randomness

Constructors

create

[Source]

new ref create(
  seed1: U64 val = 42,
  seed2: U64 val = 0)
: Randomness ref^

Parameters

  • seed1: U64 val = 42
  • seed2: U64 val = 0

Returns


Public Functions

u8

[Source]

Generate a U8 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref u8(
  min: U8 val = call,
  max: U8 val = call)
: U8 val

Parameters

  • min: U8 val = call
  • max: U8 val = call

Returns


u16

[Source]

Generate a U16 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref u16(
  min: U16 val = call,
  max: U16 val = call)
: U16 val

Parameters

  • min: U16 val = call
  • max: U16 val = call

Returns


u32

[Source]

Generate a U32 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref u32(
  min: U32 val = call,
  max: U32 val = call)
: U32 val

Parameters

  • min: U32 val = call
  • max: U32 val = call

Returns


u64

[Source]

Generate a U64 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref u64(
  min: U64 val = call,
  max: U64 val = call)
: U64 val

Parameters

  • min: U64 val = call
  • max: U64 val = call

Returns


u128

[Source]

Generate a U128 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref u128(
  min: U128 val = call,
  max: U128 val = call)
: U128 val

Parameters

  • min: U128 val = call
  • max: U128 val = call

Returns


ulong

[Source]

Generate a ULong in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref ulong(
  min: ULong val = call,
  max: ULong val = call)
: ULong val

Parameters

Returns


usize

[Source]

Generate a USize in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref usize(
  min: USize val = call,
  max: USize val = call)
: USize val

Parameters

Returns


i8

[Source]

Generate a I8 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref i8(
  min: I8 val = call,
  max: I8 val = call)
: I8 val

Parameters

  • min: I8 val = call
  • max: I8 val = call

Returns


i16

[Source]

Generate a I16 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref i16(
  min: I16 val = call,
  max: I16 val = call)
: I16 val

Parameters

  • min: I16 val = call
  • max: I16 val = call

Returns


i32

[Source]

Generate a I32 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref i32(
  min: I32 val = call,
  max: I32 val = call)
: I32 val

Parameters

  • min: I32 val = call
  • max: I32 val = call

Returns


i64

[Source]

Generate a I64 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref i64(
  min: I64 val = call,
  max: I64 val = call)
: I64 val

Parameters

  • min: I64 val = call
  • max: I64 val = call

Returns


i128

[Source]

Generate a I128 in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref i128(
  min: I128 val = call,
  max: I128 val = call)
: I128 val

Parameters

  • min: I128 val = call
  • max: I128 val = call

Returns


ilong

[Source]

Generate a ILong in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref ilong(
  min: ILong val = call,
  max: ILong val = call)
: ILong val

Parameters

Returns


isize

[Source]

Generate a ISize in closed interval [min, max] (default: [min_value, max_value]).

Behavior is undefined if min > max.

fun ref isize(
  min: ISize val = call,
  max: ISize val = call)
: ISize val

Parameters

Returns


f32

[Source]

Generate an F32 in the range from min to max (default: 0.0 to 1.0).

min is always reachable. On the default range the result is the closed interval [0.0, 1.0]: real()'s largest value rounds up to 1.0 when converted to F32, so max is produced when that top value is drawn. See Randomness for how max behaves on other ranges.

fun ref f32(
  min: F32 val = 0.0,
  max: F32 val = 1.0)
: F32 val

Parameters

  • min: F32 val = 0.0
  • max: F32 val = 1.0

Returns


f64

[Source]

Generate an F64 in the range from min to max (default: 0.0 to 1.0).

min is always reachable. On the default range the result is the half-open interval [0.0, 1.0); max (1.0) is never produced. See Randomness for how max behaves on other ranges.

fun ref f64(
  min: F64 val = 0.0,
  max: F64 val = 1.0)
: F64 val

Parameters

  • min: F64 val = 0.0
  • max: F64 val = 1.0

Returns


bool

[Source]

Generate a random Bool value.

fun ref bool()
: Bool val

Returns


shuffle[T: T]

[Source]

Shuffle the elements of the array into a random order, mutating the array.

fun ref shuffle[T: T](
  array: Array[T] ref)
: None val

Parameters

Returns