Random

object Random extends ProductReader[Random]
Companion:
class
class Object
trait Matchable
class Any
Random.type

Type members

Classlikes

final case class Coin[A, B](prob: Ex[A], gen: Random)(implicit num: NumDouble[A] { type Boolean = B; }, default: HasDefault[B]) extends Ex[B] with Act with ProductWithAdjuncts

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
object Coin extends ProductReader[Coin[_, _]]
Companion:
class
final case class Range[A](lo: Ex[A], hi: Ex[A], gen: Random)(implicit num: Num[A]) extends Ex[A] with Act with ProductWithAdjuncts

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
object Range extends ProductReader[Range[_]]
Companion:
class
final case class Until[A](hi: Ex[A], gen: Random)(implicit num: Num[A]) extends Ex[A] with Act with ProductWithAdjuncts

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
object Until extends ProductReader[Until[_]]
Companion:
class

Value members

Concrete methods

def apply(seed: Ex[Long]): Random
override def read(in: RefMapIn, key: String, arity: Int, adj: Int): Random
Definition Classes