On Tue, Jul 8, 2008 at 9:53 AM, Shubha Vishwanath Karanth < [EMAIL PROTECTED]> wrote:
> ...actually I need to allocate certain amount of money (here I mentioned > it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being > divided among 50 stocks and preferably all are integer allocations(i.e., > 5 8 56 12 etc without any decimals)... so perhaps you can reformulate your problem: instead of generating random numbers with their sum constrained to be 100, it could be dividing 100 units randomly between 50 "bins", which is, essentially, random sampling with replacement stocks <- 1:50 money <- 100 allocations <- sample(stocks, money, replace=TRUE) # here you can add a prob argument to sample() # especially if you expect the results to be something like " 5 8 56 12 etc " allocations <- table(factor(allocations, levels=stocks)) # or, equivalently, colSums(outer(allocations, stocks, "==")) I don't know if this solves your problem but at least it's guaranteed to sum to 100 and give you only integer values. Kenn [[alternative HTML version deleted]] ______________________________________________ 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.