Welcome, guest | Sign In | My Account | Store | Cart

This is just a short and simple script that generates a set of random numbers. You enter how many random numbers you want and the program will generate them.

The num is multiplied by 10 in the upper limit within the for loop to give you larger generated integers. Adjust it as needed.

Python, 9 lines
1
2
3
4
5
6
7
8
9
"""Generate a set of random numbers based on the number requested."""
import random

try:
    numbers = input("How many numbers do you want generated? ")
    for num in range(int(random.random() + 1), int(numbers) + 1):
        print(random.randint(num, num * 10))
except ValueError:
    print("Input is invalid!")

4 comments

mane 8 years, 1 month ago  # | flag

int(random.random() + 1) equals to 1, isn't it ?

Nikhil 8 years ago  # | flag

Just use this code instead:

import random

number = input("Enter number: ") for num in range(0,int(number)): print random.randint(0, number*10)

Khwab Sheth 8 years ago  # | flag

I am getting following error after inputing value.

Traceback (most recent call last): File "random.py", line 2, in <module> import random File "/var/www/python/rnd/random.py", line 6, in <module> for num in range(int(random.random() + 1), int(numbers) + 1): TypeError: 'module' object is not callable

What version of python are you using?

Created by Lance Spence on Thu, 18 Feb 2016 (MIT)
Python recipes (4591)
Lance Spence's recipes (1)

Required Modules

Other Information and Tasks