How to generate list of random integers, but only using specified integers? (Python) -
this question has answer here:
- how randomly select item list? 11 answers
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
Post a Comment