[Numpy-discussion] random number genration

eat e.antero.tammi@gmail....
Tue Mar 29 05:29:42 CDT 2011


Hi,

On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov <ater1980@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@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110329/d98acf22/attachment.html 


More information about the NumPy-Discussion mailing list