mardi 29 septembre 2015

How to generate list of random integers, but only using specified integers? (Python)

This question could be generalized to randomly creating a list of size n, containing pre-specified integers (assuming a uniform distribution). Hopefully it would look like the following:

Perhaps the syntax would look something like

randList([list of integers], size)

which could then produce something along the lines of:

randList([1,-1], 7)
>>> [1,-1,1,-1,-1,-1,1] #(random)

or

randList([2,3,4], 10)
>>> [4,3,4,2,2,4,2,3,4,3] #(random)

I am a bit new to python and everywhere I look it is always returning a range of values between a low and a high, and not specific values. Thanks




Aucun commentaire:

Enregistrer un commentaire