dsklzerpx64815631 2012-11-09 02:41 采纳率: 100%
浏览 123

在范围内生成3个随机数并且总和3个数字=此范围[重复]

Possible Duplicate:
How to make 5 random numbers with sum of 100

i am new with php . Can i ask how to make 3 random number with range an sum of 3 numbers = max value of this range.

Example : i have range 0->900; 3 random number is 213 437 250

  • 写回答

1条回答 默认 最新

  • dongta5621 2012-11-09 02:44
    关注

    Pick two random numbers between 0 and 900 inclusive. Add 0 and 900 to the list. Sort them. Your numbers are the 3 differences between successive numbers.

    For example, say you pick 503 and 117. Your sorted list is 0, 117, 503, 900. So your differences are:

    117 - 0 = 117
    503 - 117 = 386
    900 - 503 = 397

    So your three numbers are 117, 386, and 397.

    Since you only need three numbers, you can simplify the process: Generate two random numbers between 0 and 900 (inclusive). Call the larger A and the smaller B. Your numbers are B, A - B and 900 - A.

    See here.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料