lundi 18 mai 2020

Looking for a simple and efficient way to generate random numbers in python so that in every 10 number sequance the numbers won't repeat

I was wondering if there is an simple and efficient way to generate random numbers in python so that every sequence of 10 of them will be different numbers.

I tried this option:

import random
random.randint(0,100)

but after a few generations i've noticed that the generated numbers can repeat one after another so i tried to use a set of these numbers and it kinda solved the problem but it leaves some numbers behind which i need to regenerate afterwards if i need a specific amount of randomly generated numbers but after a while i was suggested with another solution:

Randlist = random.sample(range(1,101), k=10)

which works great but requires a list of integers to hold my 10 different numbers

Is there a way to do it without the list and so it wont be too complex like O(n^2) and above ?




Aucun commentaire:

Enregistrer un commentaire