On Tue, Mar 29, 2011 at 5:00 AM, Alex Ter-Sarkissov <ater1...@gmail.com> wrote: > If I want to generate a string of random bits with equal probability I run > > random.randint(0,2,size). > > What if I want a specific proportion of bits? In other words, each bit is 1 > with probability p<1/2 and 0 with probability q=1-p?
x = (np.random.random(size) < p) Setting p = .5 should produce the same results as np.random.randint(0,2,size). Note that this gives you an array of bools, not ints; use x.astype(int) if integers are important (or x.astype(np.uint8) if memory is an issue). HTH, Dan Lepage _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion