产生一个随机数序列,以获得与平均 [英] Generate a random number sequence to get and average

查看:146
本文介绍了产生一个随机数序列,以获得与平均的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待生成一个数字序列,每个数字都是70到100之间会有X上的序列中的数字,它会给平均Y的。什么这个算法是什么样子?

I am looking to generate a number sequence where each number is between 70 and 100 there will be x numbers in the sequence and it will give and average of y. What would this algorithm look like?

推荐答案

我觉得这是不可能的,他们70和100,有一个给定的平均同时之间均匀分布的。

I think it is impossible for them to be uniformly distributed between 70 and 100 and have a given average at the same time.

你可以做的就是生成随机数有一个给定的平均值,然后扩展他们融入[70,100](但他们不会均匀分布有)。

What you can do is generate random numbers that have a given average and then scale them to fit into [70, 100] (but they will not be uniformly distributed there).

  1. 生成随机数[0..1(

  1. generate random numbers [0..1(

计算其平均

乘他们都符合要求的平均

multiply all of them to match the required average

如果其中任何一个不适合到[70,100],规模个个再次通过相同的因子减少从的距离(这不改变的平均值)。 X [I] = Y +(X [I] - Y)*比例

if any of them does not fit into [70, 100], scale all of them again by reducing their distance from y by the same factor (this does not change the average). x[i] = y + (x[i] - y)*scale

您将结束与该均在范围[70,100(数字,但它们将跨越该中心位于Y A不同(但重叠)间隔均匀分布。而且,这种方法只适用于真正的/浮点数字。如果你想整数,你在你的手中有一个组合的问题。

You will end up with numbers that are all in the range [70, 100(, but they will be uniformly distributed across a different (but overlapping) interval that is centered on y. Also, this approach only works with real/floating-point numbers. If you want integers, you got a combinational problem on your hands.

这篇关于产生一个随机数序列,以获得与平均的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆