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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效