Fiveable
Fiveable

or

Log in

Find what you need to study


Light

Find what you need to study

3.15 Random Values

1 min readjanuary 9, 2023

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Generating Random Numbers

Many coding languages provide a way to generate random numbers, and College Board's is no exception. It's a good tool for many programs.

Here's what the random generator looks like in :

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-BY9uvRHSYeXU.png?alt=media&token=c40ab8ec-13e2-4cf1-ad5e-1f59b1dbd561

...and here's its equivalent in Python:

import random
c = 

Notice how you have to import the random 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 = (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 , which we'll discuss in Topic 3.16.

Key Terms to Review (4)

module

: In computer programming, a module refers to a file containing reusable code that can be imported into other programs. Modules help organize code by separating functionality into distinct files.

Pseudocode

: Pseudocode is a simplified programming language that uses plain English to outline the logic of a program. It helps programmers plan and organize their code before writing it in an actual programming language.

random.randint

: random.randint is a function in Python that generates random integers within a specified range. It takes two arguments - the lowest possible value and the highest possible value - and returns a randomly chosen integer between them.

Simulations

: Simulations are computer programs or models that imitate real-world scenarios or processes. They allow users to observe and interact with virtual environments to gain insights, test hypotheses, or make predictions.

3.15 Random Values

1 min readjanuary 9, 2023

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Generating Random Numbers

Many coding languages provide a way to generate random numbers, and College Board's is no exception. It's a good tool for many programs.

Here's what the random generator looks like in :

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-BY9uvRHSYeXU.png?alt=media&token=c40ab8ec-13e2-4cf1-ad5e-1f59b1dbd561

...and here's its equivalent in Python:

import random
c = 

Notice how you have to import the random 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 = (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 , which we'll discuss in Topic 3.16.

Key Terms to Review (4)

module

: In computer programming, a module refers to a file containing reusable code that can be imported into other programs. Modules help organize code by separating functionality into distinct files.

Pseudocode

: Pseudocode is a simplified programming language that uses plain English to outline the logic of a program. It helps programmers plan and organize their code before writing it in an actual programming language.

random.randint

: random.randint is a function in Python that generates random integers within a specified range. It takes two arguments - the lowest possible value and the highest possible value - and returns a randomly chosen integer between them.

Simulations

: Simulations are computer programs or models that imitate real-world scenarios or processes. They allow users to observe and interact with virtual environments to gain insights, test hypotheses, or make predictions.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.