gpt4 book ai didi

swift - 4个随机数总计100

转载 作者:行者123 更新时间:2023-11-30 10:14:02 25 4
gpt4 key购买 nike

我想生成 4 个介于 1 到 100 之间的随机数,以便总数加起来为 100。我该怎么做?

说出结果1) 20,10,40,30结果2 ) 33,33,33,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.

关于swift - 4个随机数总计100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31229201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com