How to Generate a List of Random Numbers in Python

To generate a list of random numbers in Python, put random.randint() inside a list comprehension: [random.randint(1, 100) for _ in range(10)] gives you ten whole numbers from 1 to 100. Need them all different? Use random.sample(range(1, 101), 10) instead:

import random

numbers = [random.randint(1, 100) for _ in range(10)]   # repeats allowed
unique = random.sample(range(1, 101), 10)               # no repeats

I ran every snippet here on Python 3.12.5 with NumPy 2.5.3, and each one calls random.seed() first, so you’ll get exactly the lists I show.

In this tutorial, we’ll build a list of random numbers in Python with integers, unique picks, floats and prices, repeatable seeds and NumPy for big lists, then simulate a week of sales.

Generate a list of random integers with randint()

random.randint(a, b) returns one integer where both ends are included. Call it once per slot in a list comprehension, and the _ just means you don’t need the loop counter:

import random

random.seed(7)
numbers = [random.randint(1, 100) for _ in range(10)]
print(numbers)
print("length:", len(numbers), "| duplicates:", len(numbers) - len(set(numbers)))

Output:

[42, 20, 51, 84, 7, 10, 69, 13, 47, 75]
length: 10 | duplicates: 0
Command Prompt output of a Python list comprehension with random.randint building ten integers from 1 to 100
Ten integers between 1 and 100 from a seeded run, with the duplicate count printed underneath.

Every call is independent, so repeats can happen. For a single value, my guide to generating a single random number in Python covers randint, randrange and friends.

Generate unique random numbers with random.sample()

random.sample(population, k) picks k items without replacement, so nothing repeats. A range works as the population:

import random

random.seed(2026)
tickets = random.sample(range(1, 70), 5)     # 5 unique numbers from 1-69
print("Unique picks:", tickets)
print("Sorted:      ", sorted(tickets))

try:
    random.sample(range(1, 11), 12)          # asking for more than exist
except ValueError as err:
    print("ValueError:", err)

Output:

Unique picks: [16, 41, 65, 66, 14]
Sorted:       [14, 16, 41, 65, 66]
ValueError: Sample larger than population or is negative
Command Prompt output of Python random.sample picking five unique numbers and raising ValueError when k is larger than the range
Five unique picks from 1 to 69, then the ValueError you get when you ask for 12 values from a range of 10.

The error text is Sample larger than population or is negative, so check k against the range size first. To pick from a list of names or products instead of numbers, see randomly selecting from a list in Python.

Generate a list of random floats and prices

random.random() returns a float from 0.0 up to (but not including) 1.0. For another range, random.uniform(a, b) scales it, and round(x, 2) turns it into a dollar amount:

import random

random.seed(11)
rates = [random.random() for _ in range(4)]
print("0-1 floats:", [round(r, 4) for r in rates])

prices = [round(random.uniform(9.99, 49.99), 2) for _ in range(6)]
print("Prices:", [f"${p:.2f}" for p in prices])
print(f"Total:  ${sum(prices):.2f}")

Output:

0-1 floats: [0.4524, 0.5598, 0.9242, 0.4657]
Prices: ['$30.30', '$33.49', '$17.38', '$30.47', '$35.19', '$41.71']
Total:  $188.54

The prices only look neat because of :.2f; real money math belongs in decimal.Decimal. For the 0-to-1 case, read generating random numbers between 0 and 1 in Python.

Want only the prices above $30.00? You can do that with a comprehension, and filtering lists in Python shows that plus filter().

How do I get the same random list every time?

Seed the generator. random.seed(42) resets the hidden state, so the same seed always produces the same sequence.:

import random

random.seed(42)
first = [random.randint(1, 50) for _ in range(6)]
random.seed(42)
second = [random.randint(1, 50) for _ in range(6)]
print(first)
print(second)
print("Same list:", first == second)

rng = random.Random(42)        # its own generator, own state
print([rng.randint(1, 50) for _ in range(6)])

Output:

[41, 8, 2, 48, 18, 16]
[41, 8, 2, 48, 18, 16]
Same list: True
[41, 8, 2, 48, 18, 16]

Both seeded lists match, and the random.Random(42) instance gives that same list too. I prefer an instance in bigger programs, since other code can’t reset it.

Once you’ve got a list you like, printing it cleanly for a report is covered in printing a list without brackets in Python.

Generate a big list of random numbers with NumPy

For thousands or millions of values, NumPy’s default_rng() is much faster than a Python loop. Note that integers(1, 101) excludes the high end, unlike randint:

import numpy as np

rng = np.random.default_rng(seed=2026)
ints = rng.integers(1, 101, size=8)          # high end is exclusive
print(ints, type(ints).__name__)
print(ints.tolist(), type(ints.tolist()).__name__)

big = rng.integers(0, 1_000, size=1_000_000)
print(f"{big.size:,} numbers, min {big.min()}, max {big.max()}")

Output:

[86 18  3 64 37 47  8 38] ndarray
[86, 18, 3, 64, 37, 47, 8, 38] list
1,000,000 numbers, min 0, max 999
Command Prompt output of NumPy default_rng creating random integer arrays, converting them with tolist, and a million-value array
rng.integers() returns an ndarray; .tolist() turns it into a plain Python list.

The older np.random.randint still works, but NumPy recommends the Generator API, which my NumPy random tutorial walks through.

Simulate a list of random daily sales in USD

This example combines the pieces. It builds seven seeded daily totals for the week of March 2, 2026, then reports the best day and the week’s total:

import random
from datetime import date, timedelta

random.seed(2026)
start = date(2026, 3, 2)
sales = [(start + timedelta(days=i), round(random.uniform(800, 2500), 2)) for i in range(7)]

for day, amount in sales:
    print(f"{day:%a %b %d, %Y}  ${amount:>9,.2f}")

best = max(sales, key=lambda s: s[1])
print(f"Best day: {best[0]:%A} at ${best[1]:,.2f}")
print(f"Week total: ${sum(a for _, a in sales):,.2f}")

Output:

Mon Mar 02, 2026  $ 1,002.50
Tue Mar 03, 2026  $ 1,654.28
Wed Mar 04, 2026  $ 1,670.10
Thu Mar 05, 2026  $ 2,262.00
Fri Mar 06, 2026  $   974.48
Sat Mar 07, 2026  $ 1,179.58
Sun Mar 08, 2026  $ 1,821.75
Best day: Thursday at $2,262.00
Week total: $10,564.69
Command Prompt output of Python generating a list of random daily sales in US dollars for a week in March 2026
Seven random daily totals formatted as dollars, with the best day and week total computed from the same list.

Each item is a tuple, and max(..., key=...) finds the top day. If you store records as objects instead, sorting a list of objects by attribute in Python explains the same key idea.

A few more random-value tutorials you can try:

Frequently asked questions

How do I generate a list of random numbers in Python?

Use a list comprehension with random.randint(), for example [random.randint(1, 100) for _ in range(10)].

How do I generate random numbers without duplicates?

Use random.sample(range(1, 101), 10). It picks without replacement, so every value is unique.

Why does random.sample() raise ValueError?

You asked for more items than the population has. k must be no larger than the range or list size.

How do I get the same random list each run?

Call random.seed(42) (any fixed number) before generating, or use a random.Random(42) instance.

How do I make a NumPy random array a Python list?

Call .tolist() on it, for example np.random.default_rng(1).integers(1, 101, size=8).tolist().

Where are the random module functions documented?

See the random module page in the Python docs.