Is there a way to create n random integers of k digits.
For example.. 2000 random integers comprising of
[0, 2, 3]
if x< 0.3: return 0
elif x<0.6: return 2
else: return 3
x = np.random.rand(num)
x = map(lamdba x:assign(x),x)
From the sounds of it, it looks like you want to generate a sequence of length
n using only the values found within the list
random.choice function combined with list comprehension is perfect for this.
The following function will generate a list of length n with each element being a random element chosen from
from random import choice def random_choices(n, k): return [choice(k) for _ in xrange(n)]
Here is the same thing as simple list comprehension.
from random import choice foo = [choice(k) for _ in xrange(n)]
*Thanks to Mr.goosberry for pointing out that
xrange should be replaced with
range in python 3.x.x.