Introduction

Published

2023-08-02

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, including
    • random.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, and
    • random.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

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

This material is for free use under either the GNU Free Documentation License or the Creative Commons Attribution-ShareAlike 3.0 United States License (take your pick).