Generate a series of random numbers that add up to N in c#

后端 未结 16 757

How do I generate 30 random numbers between 1-9, that all add up to 200 (or some arbitrary N), in C#?

I\'m trying to generate a string of digits that can add togethe

16条回答
  •  被撕碎了的回忆
    2020-12-15 22:24

    If statistical bias from true randomness is acceptable, you can add numbers up to N - [max random number], then select the last number as N - sum(selected so far).

提交回复
热议问题