【问题标题】:4 random numbers totaling 100 [duplicate]4个随机数,共100个[重复]
【发布时间】:2015-09-22 14:48:53
【问题描述】:

我想生成 4 个介于 1 和 100 之间的随机数,这样总和为 100。我该怎么做?

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

【问题讨论】:

标签: swift arc4random


【解决方案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.

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 2021-12-08
  • 2014-01-16
  • 2014-06-28
  • 2019-02-10
  • 2013-01-18
相关资源
最近更新 更多