Coin

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.

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
trait Serializable
trait ProductWithAdjuncts
trait Act
trait Ex[B]
trait Flow
trait Lazy
trait Product
trait Equals
class Object
trait Matchable
class Any

Type members

Types

type Repr[T <: Txn[T]] = IExpr[T, B] & IAction[T]

Value members

Concrete methods

override def adjuncts: List[Adjunct]
Definition Classes
ProductWithAdjuncts
override def productPrefix: String
Definition Classes
Product
def update: Act

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.

Inherited methods

final def expand[T <: Txn[LazyRef(...)]](implicit ctx: Context[T], tx: T): Repr[T]
Inherited from:
Lazy
def productElementNames: Iterator[String]
Inherited from:
Product
def productIterator: Iterator[Any]
Inherited from:
Product

Inherited fields

@transient
final protected val ref: Object
Inherited from:
Lazy