Ask coding questions

← Back to all posts
My code for a random number generator keeps giving the same outcome
niteeshtapre (0)

This is the code

from random import seed
from random import randint
print('Numbers generated are below')
seed(1)
for _ in range(10):
value = randint (1 , 10)

print (value)

The outcome is always
3
10
2
5
2
8
8
8
7
4

Commentshotnewtop
PDanielY (983)

You have to use a different seed every time

niteeshtapre (0)

@PDanielY Is there a way I can change the seed automatically every time?

PDanielY (983)

@niteeshtapre but why? you don't even need the seed function. The only purpose of the seed command is to make random.randit have the same value