更多的CPU /时间效率的方式来得到n个准随机数比以N兰特()调用?随机数、兰特、效率、方式

2023-09-11 07:12:22 作者:快手搞笑昵称,快手搞笑名字大全

这是一个延续的another问题如何有效地让准随机数。

This is a continuation of another question about efficiently getting quasi-random numbers.

我需要得到n独特的伪随机数,偏置/配送质量是没什么大不了的。我可以让他们更多的CPU /时间效率比使用N个调用RAND()或/ dev /随机等?也许用在一些随机的号码或类似的东西,一些数学/按位操作。或者用precomputed表或...

I need to get N unique quasi-random numbers, bias/distribution quality is no big deal. Can I get them more CPU/time-efficiently than using N calls to rand() or /dev/random etc? Maybe using some math/bitwise manipulations on few random numbers or something like that. Or using precomputed tables or...

N可以是相当大的像10000或1:1000000。

N can be quite big like 10000 or 1000000.

感谢。

推荐答案

我发现simething这样这里:

I found simething like this here:

m_w = <choose-initializer>;    /* must not be zero */
m_z = <choose-initializer>;    /* must not be zero */

uint get_random()
{
    m_z = 36969 * (m_z & 65535) + (m_z >> 16);
    m_w = 18000 * (m_w & 65535) + (m_w >> 16);
    return (m_z << 16) + m_w;  /* 32-bit result */
}