Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Generate a random double between -1 and 1
From
Aaron Kirkman <[email protected]>
To
[email protected]
Subject
Re: st: Generate a random double between -1 and 1
Date
Sun, 2 Sep 2012 16:09:48 -0500
Hi Steve,
Good point. My number theory was a bit off in my original logic, and
the blog post Nick linked to clears all that up.
Thank you,
Aaron
On Sun, Sep 2, 2012 at 3:50 PM, Steve Samuels <[email protected]> wrote:
>
> Your statement that
>> "...multiplying 2 * runiform() excludes half the
>> possible values between -1 and 1."
> is incorrect, as the limits of -1 + 2*runiform() are -1 + 2*0 = -1, and -1 +2*1 = +1.
>
>
> Steve
>
>
>
> On Sep 2, 2012, at 3:45 PM, Nick Cox wrote:
>
> See <http://blog.stata.com/2012/08/29/using-statas-random-number-generators-part-3-drawing-with-replacement/>
> and prequels.
>
> Nick
>
> On Sun, Sep 2, 2012 at 8:26 PM, Aaron Kirkman <[email protected]> wrote:
>> I have a situation where I need to generate random real numbers
>> between -1 and 1, and I'm wondering if there is a better way to
>> accomplish this. Right now, I use this:
>>
>> clear
>> set obs 100000000
>> gen double eps = -1 + 2 * runiform()
>> summ eps
>>
>> While this is probably acceptable, as the theoretical mean is 0, it's
>> problematic because multiplying 2 * runiform() excludes half the
>> possible values between -1 and 1. Is there a built-in way to do this
>> in a way that won't exclude values, or is this method sufficient? In
>> practice, I may generate as few as 30 random numbers and as many as
>> 100,000,000 (if that's relevant).
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/