- Companion:
- class
Type members
Classlikes
A random boolean with a given probability. If prob
is zero, the output will
always be false
, if prob
is one, the output will always be true
, if
prob
is 0.5
, the likelihood of false
and true
is equal.
A random boolean with a given probability. If prob
is zero, the output will
always be false
, if prob
is one, the output will always be true
, if
prob
is 0.5
, the likelihood of false
and true
is equal.
This is both an expression and an action. The action draws a new random number, the expression reports the last drawn value.
Example:
val gen = Random()
val coin = gen.coin(0.4)
Act(
coin, // draw new number
PrintLn("Random coin (slightly favouring false): " ++ coin.toStr) // print current value
)
- Companion:
- object
A random number between a given lo
and a given hi
boundary.
The boundaries are inclusive
for integer numbers. For floating point numbers, the hi
bound is exclusive.
A random number between a given lo
and a given hi
boundary.
The boundaries are inclusive
for integer numbers. For floating point numbers, the hi
bound is exclusive.
This is both an expression and an action. The action draws a new random number, the expression reports the last drawn value.
Example:
val gen = Random()
val r1to10 = gen.range(1, 10)
Act(
r1to10, // draw new number
PrintLn("Random number (1 to 10): " ++ r1to10.toStr) // print current value
)
- Companion:
- object
A random number between zero (inclusive) and a given hi
boundary (exclusive).
hi
may be negative, but it must not be zero.
A random number between zero (inclusive) and a given hi
boundary (exclusive).
hi
may be negative, but it must not be zero.
This is both an expression and an action. The action draws a new random number, the expression reports the last drawn value.
Example:
val gen = Random()
val r100 = gen.until(100)
Act(
r100, // draw new number
PrintLn("Random number: " ++ r100.toStr) // print current value
)
- Companion:
- object