[R] Generate random numbers under constrain

Boris Steipe
Sat, 22 Nov 2014 15:29:18 -0000

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]]