Learn Before
Example

Simulating a Fair Coin Toss

To simulate a fair coin toss (an event with a 0.5 probability), we can use a random number generator that outputs continuous values uniformly distributed in the interval [0, 1]. Since the probability of a generated value falling into any sub-interval [a, b] subset [0, 1] is bab - a, the probability of the value falling in [0, 0.5] is 0.5, and in (0.5, 1] is also 0.5. Therefore, we can simulate the two equally likely outcomes of a coin toss by testing whether the generated float is greater than 0.5.

0

1

Updated 2026-06-29

Tags

D2L

Dive into Deep Learning @ D2L