Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. To generate a random number between 1 and 10 in Python, the most common approach is to use the random module’s randint() function, which returns an integer within the specified inclusive range.

    Example:

    import random

    # Generate a single random integer between 1 and 10
    num = random.randint(1, 10)
    print(num)
    Copied!

    This will print any integer from 1 to 10, including both endpoints.

    Using random.randrange() This method works similarly but excludes the upper bound.

    import random

    num = random.randrange(1, 11) # upper bound is exclusive
    print(num)
    Copied!

    Here, randrange(1, 11) ensures numbers from 1 to 10 are possible.

    Generating Multiple Random Numbers You can use list comprehension for multiple values:

    import random

    nums = [random.randint(1, 10) for _ in range(5)]
    print(nums)
    Copied!

    This produces a list of five integers between 1 and 10.

    Using random.uniform() for Floats If you need floating-point numbers:

    import random

    num = random.uniform(1, 10)
    print(num)
    Copied!

    This returns a float between 1.0 and 10.0, inclusive.

    Feedback
  2. random — Generate pseudo-random numbers — Python …

    Mar 25, 2026 · Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying …

  3. Generate a Random Number in Python - Examples

    • In this tutorial of Python Examples, we learned how to generate a random number in Python with the help of well detailed examples.
    See more on pythonexamples.org
  4. Python Random Module - W3Schools

    23 rows · Python has a built-in module that you can use to make random numbers. The random module has a set of methods:

  5. Generate Random Number in Range Python - PyTutorial

    3 days ago · Learn how to generate random numbers within a specific range in Python using the random module's randint, randrange, and uniform functions.

  6. How to Generate a Random Number in Python

    Python offers a large number of modules and functions to use random data. This article will guide you to include these functions in your code and provide code snippets for your convenience.

  7. How To Generate A List Of Random Numbers In Python?

    Feb 27, 2025 · Learn how to generate a list of random numbers in Python using `random.randint ()`, `random.uniform ()`, and list comprehension. This guide includes examples.

  8. Python random () Function | Docs With Examples - Hackr

    Apr 25, 2025 · Python's random module with examples. Generate random numbers, shuffle lists, select random elements, and use statistical distributions for …

  9. random | Python Standard Library – Real Python

    The Python random module provides tools for generating random numbers and performing random operations. These are essential for tasks such as simulations, …

  10. Python Random Module: Generate Random Numbers and Data

    Jun 16, 2021 · Python Random Module: Generate Random Numbers and Data This lesson demonstrates how to generate random data in Python using a random module. In Python, a random module …