В момента ресурсът е наличен само на английски

How to generate random numbers in Python Pro Preview

When you install SPIKE, several commonly used libraries are installed along with it. One of these is the "random" library. This library allows us to generate random numbers within a range that we choose.

Each time the program starts, the generated numbers will usually be different, although sometimes the same number may appear again. After all, they are random!

Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео

Абонирай се

  • #2598
  • 12 Mar 2026

In order to use this library, we must import it first. To do this, add the following line to the beginning of your program:

import random

Now we can use the commands from this library!

To generate a random number, we can use the random.randint() command. This command has two input parameters:

  1. The smallest number it can select;
  2. The largest number it can select.

Here is an example where we store a random number between 0 and 10 in a variable called "random_number":

random_number = random.randint(0, 10)