[Numpy-discussion] random number genration

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


On Tue, Mar 29, 2011 at 1:29 PM, eat <e.antero.tammi@gmail.com> wrote:

> 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
>
Or:
In []: bs= ones(1e6, dtype= int)
In []: bs[rand(1e6)< 1./ 10]= 0
In []: bs.sum()/ 1e6
Out[]: 0.89983

>
> 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/213da3b7/attachment-0001.html 


More information about the NumPy-Discussion mailing list