samedi 3 juin 2017

Python - Random sample from a range whilst avoiding certain values

I have been reading up about the random.sample() function in the random module and have not seen anything that solves my problem.

I know that using random.sample(range(1,100),5) would give me 5 unique samples from the 'population'...

I would like to get a random number in range(0,999). I could use random.sample(range(0,999),1) but why then am I thinking about using random.range() ?

I need the random number in that range to not match any number in a separate array (Say, [443,122,738])

Is there a relatively easy way I could go about doing this?

Also, I am pretty new to python and am definitely a beginner -- If you would like me to update the question with any information I may have missed then I will.

EDIT: Accidentally said random.range() once. Whoops.




Aucun commentaire:

Enregistrer un commentaire