[R] runif with condition

Duncan Murdoch murdoch.duncan at gmail.com
Mon Jan 9 16:36:00 CET 2012


On 09/01/2012 10:27 AM, David Winsemius wrote:
> On Jan 9, 2012, at 10:06 AM, arunkumar1111 wrote:
>
> >  Hi
> >  I want to generate 4 random number which sum up to 100 always
>
> "Random" plus condition == "non-random"
>
> Perhaps you want 3 "random" numbers conjoined to the difference of
> their sum and 100? Or perhaps you want 4 "random" numbers multiplied
> by 100/sum(.)
>
> (In either case you will not be getting "4 random numbers".)

There's quite a lot of ambiguity in the word "random".  For example, you 
seem to be assuming a "random number"  has to come from a uniform 
distribution, but I would say any distribution except the trivial point 
mass on one point is "random".

So an answer to the original query in my usage is the 4-tuple (a,b,c,d):

a <- 0
b <- 0
c <- runif(1)
d <- 100-c

but this is probably not what was wanted.

Duncan Murdoch



More information about the R-help mailing list