4个随机数,共计100个

时间:2015-07-05 10:05:28

标签: swift arc4random

我想在1到100之间生成4个随机数,这样总数就会增加到100个。我该怎么做?

说result1)20,10,40,30 结果2)33,33,33,1 谢谢

1 个答案:

答案 0 :(得分:1)

要走的路是:

Step 1: Generate four random numbers between 0 and 1
Step 2: Add these four numbers
Step 3: Divide each of the four numbers by the sum,
Step 4: Multiply by 100, and round to the nearest integer.