Mahek Shah
Mahek Shah

Reputation: 495

Creating random list of number in python within certain range

I want to create 10,000 random numbers withing the range of 1 to 100.

How can I do with python?

I can use for loop and with each for loop I can use random.sample() or random.random() function.

Is there any other way, without using any for loop I can generate it with built-in function ?

Upvotes: 0

Views: 897

Answers (1)

Adelina
Adelina

Reputation: 11881

For python 3.6:

import random

my_randoms = random.choices(range(1,100), k=10000)
print(my_randoms)

For older would still need to use loops:

my_randoms = [random.randrange(100) for x in range(10000)]

Upvotes: 4

Related Questions