Introduction
Here we will learn about some of the abundant uses of randomness. Randomness is useful in games (shuffle a deck, roll a die), but it’s also useful for modeling and simulating a staggering variety of real world processes.
Learning objectives
- You will understand why it is useful to be able to generate pseudo-random numbers or make pseudo-random choices in a computer program.
- You will learn how to use some of the most commonly-used methods from Python’s
random
module, includingrandom.random()
to generate a pseudo-random a floating point number in the interval [0.0, 1.0),random.randint()
to generate a pseudo-random integer in a specified interval,random.choice()
to make a pseudo-random selection of an item from an iterable object, andrandom.shuffle()
to shuffle a list.
- You will understand the role of a seed in the generation of pseudo-random numbers, and understand how setting a seed makes predictable the behavior of a program incorporating pseudo-randomness.
Terms introduced
- Monte Carlo simulation
- pseudo-random
random
module- random walk
- seed
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.