[Numpy-discussion] random number genration

eat e.antero.tammi at gmail.com
Tue Mar 29 06:29:42 EDT 2011


Hi,

On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov <ater1980 at 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?
>
Would it be sufficient to:
In []: bs= ones(1e6, dtype= int)
In []: bs[randint(0, 1e6, 1e5)]= 0
In []: bs.sum()/ 1e6
Out[]: 0.904706

Regards,
eat

>
> thanks
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110329/d98acf22/attachment.html>


More information about the NumPy-Discussion mailing list