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
Value members
Concrete methods
Convenient method that returns the Coin
itself. This can be used
for additional clarity when writing Bang() ---> coin.update
instead of Bang() ---> coin
.
Convenient method that returns the Coin
itself. This can be used
for additional clarity when writing Bang() ---> coin.update
instead of Bang() ---> coin
.