Learn Before
Example

Simulating a Fair Coin Toss

To simulate an event with a 0.50.5 probability, such as a fair coin toss, we can utilize a random number generator that outputs continuous values in the interval [0,1][0, 1]. By testing whether the generated float is greater than 0.50.5, we assign the two outcomes with equal likelihood, since the probability of the value falling in either the [0,0.5][0, 0.5] or (0.5,1](0.5, 1] sub-interval is exactly ba=0.5b-a = 0.5.

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L