WeightedCoin

class WeightedCoin(val probability: Double, random: Random = Random)(source)

A biased coin that lands heads (true) with the given probability.

Useful for simulating Bernoulli trials with a specific success probability.

Example:

val coin = WeightedCoin(0.7)
coin.flip() // true with 70% probability

Parameters

probability

the probability of heads (true). Must be in 0, 1.

random

the random number generator. Defaults to Random.

Constructors

Link copied to clipboard
constructor(probability: Double, random: Random = Random)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun flip(): Boolean

Flips the coin and returns the result.