发电排序的随机数,而不幂为何?随机数、而不

2023-09-11 06:10:03 作者:过度幻想

我要寻找一个数学公式或算法,它可以产生均匀随机数的范围为[0,1]升序排序没有除法运算符的帮助。我很希望在跳过除法运算,因为我实现它的硬件。谢谢你。

I am looking for a math equation or algorithm which can generate uniform random numbers in ascending order in the range [0,1] without the help of division operator. i am keen in skipping the division operation because i am implementing it in hardware. Thank you.

推荐答案

生成号码上升(或下降)为了表示他们产生顺序,如果有合理的分布。即,反过来,意味着我们需要知道的最小的一组大小N的分布,然后在每一个阶段,我们需要使用调节来确定基于我们已经看到下一个值。数学上,这些都是简单的,除了避免分裂的问题。

Generating the numbers in ascending (or descending) order means generating them sequentially but with the right distribution. That, in turn, means we need to know the distribution of the minimum of a set of size N, and then at each stage we need to use conditioning to determine the next value based on what we've already seen. Mathematically these are both straightforward except for the issue of avoiding division.

您可以生成N个统一的最小值(0,1)的从一个单一的统一使用U形算法(0,1)的随机数分= 1 - U **(1 / N ),其中 ** 表示幂。换言之,N个的补个的均匀根部具有相同的分布为N制服的最小在范围[0,1],然后可以进行调整以任何其他间隔长度你喜欢的。

You can generate the minimum of N uniform(0,1)'s from a single uniform(0,1) random number U using the algorithm min = 1 - U**(1/N), where ** denotes exponentiation. In other words, the complement of the Nth root of a uniform has the same distribution as the minimum of N uniforms over the range [0,1], which can then be scaled to any other interval length you like.

调理方面基本上说,已生成的第k值已经吃掉了原区间的某一部分,而最小的NK值,我们现在想的是,扩展到其余的范围。

The conditioning aspect basically says that the k values already generated will have eaten up some portion of the original interval, and that what we now want is the minimum of N-k values, scaled to the remaining range.

结合两块得到以下逻辑。产生最小的N个制服,它由剩余区间长度(1第一次)比例绘制,并作出这样的结果,我们已生成的最后的值。随后生成最小的N-1的制服,它由剩余的时间尺度,并将其添加到最后一个给你下一个值。车床,冲洗,重复,直到你做了他们所有。下面的Ruby实现提供了distributionally正确的结果,假设你已经在此之前读取或指定N:

Combining the two pieces yields the following logic. Generate the smallest of the N uniforms, scale it by the remaining interval length (1 the first time), and make that result the last value we have generated. Then generate the smallest of N-1 uniforms, scale it by the remaining interval length, and add it to the last one to give you your next value. Lather, rinse, repeat, until you have done them all. The following Ruby implementation gives distributionally correct results, assuming you have read in or specified N prior to this:

last_u = 0.0
N.downto(1) do |i|
  p last_u += (1.0 - last_u) * (1.0 - (rand ** (1.0/i)))
end

但我们有那个讨厌我日的根,它使用部门。但是,如果我们知道ň时间​​提前,我们可以$ P $ 1 P-计算整数的倒数为N下线和表他们。

but we have that pesky ith root which uses division. However, if we know N ahead of time, we can pre-calculate the inverses of the integers from 1 to N offline and table them.

last_u = 0.0
N.downto(1) do |i|
  p last_u += (1.0 - last_u) * (1.0 - (rand ** inverse[i]))
end

我不知道有什么办法不使用指数得到分配顺序正确的行为。如果这是一个表明,塞,你将不得不放弃的过程中无论是顺序性或均匀性的要求。

I don't know of any way get the correct distributional behavior sequentially without using exponentiation. If that's a show-stopper, you're going to have to give up on either the sequential nature of the process or the uniformity requirement.