[R] Generate random numbers under constrain
Boris Steipe
boris.steipe at utoronto.ca
Sat Nov 22 17:01:38 CET 2014
Of course they are random. But they can't all be randomly picked from [0,1).
By scaling them, one is effectively scaling the interval from which they are picked.
B.
Nb: the scaling procedure will work for any probability distribution.
On Nov 22, 2014, at 10:54 AM, Ranjan Maitra <maitra.mbox.ignored at inbox.com> wrote:
> I don't understand this discussion at all.
>
> n random numbers constrained to have sum <=1 are still random. They are not all independent.
>
> That said, the original poster's question is ill=formed since there can be multiple distributions these random numbers come from.
>
> best wishes,
> Ranjan
>
>
>
> On Sat, 22 Nov 2014 10:29:18 -0500 Boris Steipe <boris.steipe at utoronto.ca> wrote:
>
>> These are contradictory requirements: either you have n random numbers from the interval [0,1), then you can't guarantee anything about their sum except that it will be in [0,n). Or you constrain the sum, then your random numbers cannot be random in [0,1). You could possibly scale the random numbers:
>> n <- 13
>> x <- runif(n)
>> x <- x / sum(x)
>> x; sum(x)
>>
>> This will guarantee that their sum is 1 (to numerical accuracy), but your numbers are then effectively drawn from the interval [0,2/n) for large n.
>>
>> B.
>>
>>
>> On Nov 22, 2014, at 9:29 AM, Ragia Ibrahim <ragia11 at hotmail.com> wrote:
>>
>>>
>>> Dear all,
>>> I use R 3.1.1 for Windows.
>>> kindly how can I generate n number of random numbers with probability from [0,1]
>>> and their sum must not be more than one
>>> thanks in advance
>>> Ragia
>>>
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> --
> Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. Please respond to the mailing list if appropriate. For those needing to send personal or professional e-mail, please use appropriate addresses.
>
> ____________________________________________________________
> FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
> Visit http://www.inbox.com/photosharing to find out more!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list