On Thu, Jul 19, 2012 at 04:12:07AM -0700, arunkumar1111 wrote: > hi > > My inputs is min=(10,10,10,10,10) and max=(100,100,100,100,100) > total = 300 > i have to generate 5 numbers between min and max and those numbers should > sum upto total
Hi. Try the following. while (1) { x <- 10 + 250*diff(c(0, sort(runif(4)), 1)) if (all(x <= 100)) break } x [1] 99.32985 77.04346 65.49482 33.98516 24.14672 sum(x) [1] 300 According to some tests, the average number of repetitions of the while loop is about 5. Hope this helps. Petr Savicky. ______________________________________________ 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.