lundi 19 février 2018

Generate n sets of random numbers without a loop

so when I generate 1000 sets of random numbers (0..2000) in Python, I can easily do something like this:

iters = 1000
randIdx = []
numbers = range(0, 2000)
for i in range(iters):
        randIdx.append(random.sample(numbers, 8))

The problem is that the code is VERY slow. Is there a way to avoid the for loop to tell the function to just put out 1000 sets or is there some kind of workaround? I thought of just generating 8000 random numbers but the problem occurs that it is not possible to do that when in a set of 8 numbers duplicates aren't allowed!




Aucun commentaire:

Enregistrer un commentaire