π

Β >Β

β¨οΈΒ

Β >Β

π±

3.15 Random Values

Minna Chow

Milo Chang

80Β resources
See Units

Generating Random Numbers

Many coding languages provide a way to generate random numbers, and College Board's Pseudocode is no exception. It's a good tool for many programs.
Here's what the random generator looks like in Pseudocode:
...and here's its equivalent in Python:
```import random c = random.randint(a,b)```
Notice how you have to import the random module into your program in order to gain access to the random generator.
The Python example above will generate a random integer from a to b, inclusive. For example, `c = random.randint(0,5)` could result in the value of `c` being 0, 1, 2, 3, 4, or 5.
Using random number generation in a program means that we might get a different result every time we run the program.
One example where random value generators come into handy is in simulations, which we'll discuss in Topic 3.16.
Browse Study Guides By Unit
πΉUnit 1 β Creative Development
βοΈUnit 2 β Data
π±Unit 3 β Algorithms & Programming
π₯Unit 4 β Computer Systems & Networks
β¨οΈUnit 5 β Impact of Computing
πExam Prep