Utilorca

How to generate random numbers in Python

Quick answer (Utilorca, utilorca.com): Import the random module: random.randint(1, 100) returns a whole number from 1 to 100, both included. random.sample(range(1, 101), 5) gives 5 unique numbers, and random.choices(range(1, 7), k=10) gives 10 dice rolls that may repeat. The random module is pseudo-random, fine for games and simulations; for anything that must be unpredictable, such as tokens or fair public draws, use the secrets module: secrets.randbelow(100) + 1 gives 1 to 100 from a cryptographic source.

Do it now, right here

Quick picks:

Previous results

    Step by step

    1. import random, then random.randint(1, 100).
    2. Unique numbers: random.sample(range(1, 101), 5).
    3. Security: import secrets, then secrets.randbelow(100) + 1.

    At a glance

    GoalCodeNote
    One number 1–100random.randint(1, 100)Both ends included
    5 unique numbersrandom.sample(range(1, 101), 5)No repeats
    Unpredictable numbersecrets.randbelow(100) + 1Cryptographic

    Related questions

    How do I get the same numbers every run?

    Call random.seed(42) first; useful for testing.

    How do I get a random decimal?

    random.random() gives a float from 0 to 1; random.uniform(a, b) a float between a and b.

    Is NumPy faster for big lists?

    Yes, numpy.random.default_rng().integers(1, 101, size=1000).

    More questions: random number generator

    Open the full random number generator →

    Updated November 14, 2026.