Generate 100 Random Numbers in Python: Easy Steps

How-to basics · Updated November 23, 2026

Generating 100 random numbers in Python is a common task for simulations, testing, data sampling, or games. This guide shows you the simplest and most efficient ways to do it using Python’s built-in random module, plus a modern alternative with numpy if you need arrays. No prior experience beyond basic Python syntax is required.

What You’ll Need

  • Python 3 installed on your computer (download from python.org if needed).
  • A code editor or IDE (like VS Code, PyCharm, or IDLE) or a terminal/command prompt.
  • Basic familiarity with running Python scripts or using the interactive shell.

Step-by-Step

  1. Open your Python environment. Launch IDLE, a terminal, or your preferred editor. Create a new Python file (e.g., random_numbers.py) or start an interactive session.
  2. Import the random module. At the top of your file, type import random. This gives you access to all the random number functions.
  3. Generate a list of 100 random integers. Use a list comprehension with random.randint(). For integers between 1 and 100 (inclusive), write:
    numbers = [random.randint(1, 100) for _ in range(100)]

    This creates a list named numbers containing 100 random integers. The underscore _ is a common placeholder for the loop variable you don’t need.

  4. Generate 100 random floats. If you need decimal numbers, use random.random() which returns a float between 0.0 and 1.0:
    floats = [random.random() for _ in range(100)]

    For floats in a specific range, multiply and add: [random.uniform(10, 20) for _ in range(100)] gives floats between 10 and 20.

  5. Generate 100 numbers from a range with a step. Use random.randrange() to get numbers like even numbers from 0 to 100:
    evens = [random.randrange(0, 101, 2) for _ in range(100)]

    This picks from 0, 2, 4, …, 100.

  6. Generate 100 numbers from a specific distribution (optional). For a normal (Gaussian) distribution, use random.gauss(mu, sigma):
    normal_numbers = [random.gauss(0, 1) for _ in range(100)]

    This gives 100 numbers with mean 0 and standard deviation 1.

  7. Generate a list of 100 unique random integers (sampling without replacement). If you need distinct numbers, use random.sample():
    unique_numbers = random.sample(range(1, 1000), 100)

    This picks 100 unique numbers from 1 to 999. Note: the range must have at least 100 elements.

  8. Generate a numpy array of 100 random numbers (optional, for advanced use). If you have NumPy installed, you can create an array more efficiently:
    import numpy as np
    arr = np.random.randint(1, 100, size=100)  # integers
    arr_float = np.random.random(100)  # floats 0-1

    This is faster for large-scale operations and gives you array methods.

  9. Use the numbers. Now you can print them, save to a file, or use them in calculations. For example, to print all 100:
    print(numbers)

    Or iterate: for num in numbers: print(num)

Common Mistakes

  • Forgetting to import random. If you call random.randint without importing, you’ll get a NameError.
  • Using random.randint(1, 100) with a loop that runs 101 times. The range(100) gives exactly 100 iterations; using range(101) gives 101 numbers.
  • Confusing randint and randrange. randint(a, b) includes both endpoints; randrange(a, b) excludes b.
  • Expecting unique numbers from randint. It can repeat values. Use sample if you need uniqueness.
  • Using random.sample with a range smaller than 100. This raises a ValueError because it can’t pick 100 unique items from fewer than 100.
  • Not storing the list. If you just write [random.randint(1,100) for _ in range(100)] without assigning it to a variable, the list is created and discarded.

Tips

  • Set a random seed for reproducibility. Add random.seed(42) before generating numbers to get the same sequence every run. This is crucial for debugging or sharing results.
  • Use list comprehensions instead of loops. They are more concise and faster than a for loop with append().
  • For large datasets, consider NumPy. It’s significantly faster and memory-efficient for thousands of numbers.
  • To generate numbers in a different range, adjust the arguments. For example, randint(-10, 10) gives negatives.
  • Save the numbers to a file if you need them later. Use with open('numbers.txt', 'w') as f: f.write('\n'.join(map(str, numbers))).
  • Check the type of numbers. randint returns integers, random() returns floats. If you need a specific type, be mindful.

Troubleshooting

  • NameError: name ‘random’ is not defined. You forgot the import. Add import random at the top of your script.
  • ValueError: Sample larger than population or is negative. This happens with random.sample when the range has fewer numbers than you request. Increase the range or reduce the sample size.
  • TypeError: ‘range’ object is not callable. This occurs if you accidentally named a variable range earlier. Rename it and restart your session.
  • Numbers are all the same. This can happen if you call random.seed() with the same value every time you generate. Remove the seed or change it.
  • List is longer or shorter than 100. Check your range() argument. range(100) gives 100 items, range(101) gives 101.
  • ImportError: No module named ‘numpy’. If you used the NumPy code, install it with pip install numpy in your terminal.

Frequently Asked Questions

  • How do I generate 100 random numbers without duplicates? Use random.sample(range(start, end), 100) where the range has at least 100 numbers. For example, random.sample(range(1, 1000), 100) gives 100 unique integers.
  • Can I generate random numbers in a specific range like 5 to 15? Yes. For integers, use random.randint(5, 15). For floats, use random.uniform(5, 15).
  • What’s the difference between random.randint and random.randrange? randint(a, b) includes both endpoints (a and b). randrange(a, b) includes a but excludes b. So randrange(1, 10) gives 1-9, while randint(1, 10) gives 1-10.
  • How do I make the random numbers reproducible? Call random.seed(42) (or any integer) before generating. This makes the sequence the same every time you run the script.
  • Is there a faster way to generate 100 random numbers? Using NumPy with np.random.randint is faster for large arrays, but for only 100 numbers, the standard library is fine.
  • Can I generate random numbers from a normal distribution? Yes, use random.gauss(mu, sigma) for a single number, or a list comprehension: [random.gauss(0, 1) for _ in range(100)].

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.