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


this question has answer here:

this question generalized randomly creating list of size n, containing pre-specified integers (assuming uniform distribution). following:

perhaps syntax like

randlist([list of integers], size) 

which produce along 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 bit new python , everywhere returning range of values between low , high, , not specific values. thanks

vals = [random.choice(integers) _ in range(num_ints)] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -