java random percentages

Posted by erw on Stack Overflow See other posts from Stack Overflow or by erw
Published on 2010-06-09T16:51:45Z Indexed on 2010/06/09 17:02 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

I need to generate n percentages (integers between 0 and 100) such that the sum of all n numbers adds up to 100.

If I just do nextInt() n times, each time ensuring that the parameter is 100 minus the previously accumulated sum, then my percentages are biased (i.e. the first generated number will usually be largest etc.). How do I do this in an unbiased way?

© Stack Overflow or respective owner

Related posts about java

Related posts about algorithm