Hi I want to generate 4 random number which sum up to 100 always Please help ----- Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/runif-with-condition-tp4278704p4278704.html Sent from the R help mailing list archive at Nabble.com.
On Mon, Jan 9, 2012 at 10:06 AM, arunkumar1111 <akpbond007 at gmail.com> wrote:> Hi > I want to generate 4 random number which sum up to 100 always > > Please helpThis sounds like homework. But you might want to search rseek.org for information on random numbers, and to ponder the mysteries of addition and division. Sarah -- Sarah Goslee http://www.functionaldiversity.org
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".) -- David Winsemius, MD West Hartford, CT
Try foo <- function(n){ x <- runif(n) x * 100 / sum(x) } foo(4) HTH, Jorge.- On Mon, Jan 9, 2012 at 10:06 AM, arunkumar1111 <> wrote:> Hi > I want to generate 4 random number which sum up to 100 always > > Please help > > > ----- > Thanks in Advance > Arun > -- > View this message in context: > http://r.789695.n4.nabble.com/runif-with-condition-tp4278704p4278704.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
On Jan 9, 2012, at 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"An offlist correspondent has disputed this and I can admit that I was perhaps too hasty here. If the sample space is defined, for instance, as the set of all positive integers whose sum is 100, then it might be possible to say that one randomly drawn instance of such a 4-tuple would be "4 random numbers". What I meant to suggest is that the sum- to-100-constraint means that once a set of 3 numbers from the appropriate sample space have been drawn, that the fourth is no longer "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".) > > --David Winsemius, MD West Hartford, CT
This question *screams* for the standard response: "What is the problem you are trying to solve?" I can think of two related problems off the top of my head. 1) Write a function which generates the four bridge hands from a well-shuffled deck. 2) Throw 100 pennies into a big "shaker" with four output ports of equal size and see how many pennies end up in each port. Each of these problems has "hidden" constraints. So far, since the OP hasn't weighed in, we have no idea what his constraints are. -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est."
AlanM said, "Consider the pair {X, 1-X} where X is sampled from a uniform(0,1) distribution. The quantity 1- X also comes from a uniform(0,1) distribution and therefore is probabilistic and not deterministic. The sum of independent random variables is itself a random variable. If X1, X2 & X3 are uniformly distributed, then the distribution of Y = X1 + X2 + X3 can be determined (i.e. Y is probabilistic and NOT deterministic). Y is a random variable, but it is correlated with X1, X2 and X3. The set {X1, X2, X3, 100 - (X1 + X2 + X3) } contains 4 random variables, however they are neither independent or identically distributed. If you are curious, check this out. Deriving the Probability Density for Sums of Uniform Random Variables Edward J. Lusk and Haviland Wright The American Statistician Vol. 36, No. 2 (May, 1982), pp. 128-130" (endquote) Be *very* careful about how you state the problem. The quantity (1-X), once you know the value of X, is deterministic. The confusion arises, I think, in that if you do NOT know the value of X, then both X and (1-X) are unknown and probabilistic. But, rather like entangled photons :-), once you know one of the values, you immediately know the other. I'll sign off with the reminder that, back when Marylin vos Savant first published the Monte Hall problem, a number of people with PhDs in math, some of whom claimed to be statisticians, angrily supported the incorrect answer. Carl -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est."