免费乘以持有期
我试图弄清楚特定 CMWC 伪随机数生成器的周期是多少。
维基百科页面有一些标准 MWC 和 CMWC 不同参数周期的示例,但并没有真正回答如何计算。
对于给定的乘数、种子数 r 和基数 b,是否有一种简单的方法来计算这个值?
例如,假设我有以下参数(对于 CMWC):
b=2^32-1
a=4294966362
r=32
我已验证 p=a*b^r+1
是质数。
编辑:哎呀,复制了错误的值。修复了它,所以 p 现在应该是素数。
I'm trying to figure out what the period of a particular CMWC pseudo-random number generator would be.
The wikipedia page has some examples of the period of different parameters for both a standard MWC and CMWC, but doesn't really answer how this is calculated.
Is there an easy way to calculate this for a given multiplier, r number of seeds, and base b?
For example, say I have the following parameters (for a CMWC):
b=2^32-1
a=4294966362
r=32
I have verified that p=a*b^r+1
is prime.
edit: oops, copied the wrong a value. Fixed it so p should be prime now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 b 的阶数为 p-1 时,b 是原根,因此 b^k 可以假定从 1 到 p-1 的每个值,具体取决于 k 的值。
元素的阶数是最小 s,其中 b^s=1 (mod p)。
b 是原根当且仅当对于 phi(p) 的每个 k 除数 b^(phi(p)/k) != 1 (!= 表示不同),并且 phi(p) = (p-1 ) 是欧拉 totient 函数 (http://en.wikipedia.org/wiki/Euler%27s_totient_function)。
在您的示例中:
- phi(p) = a*b^r = p - 1.
- a 的约数为 {1, 2, 3, 31, 23091217, 4294966362}。
- b 的约数为 {1, 3, 5, 17, 257, 65537, 4294967295}。
所以,(p-1) = 2*(3^33)*(5^32)*(17^32)*31*(257^32)*(65537^32)*23091217。
p-1 有 322,570,512 个除数 (http://en.wikipedia.org/wiki/Divisor_function)
通过模幂,可以看到
b^((p-1)/3) = 1 (mod p)
所以b的顺序与p-1不同。
最好选择约数较少的数字a和b,那么p-1也会有较少的约数,并且很容易计算(phi(p) / k ) 对于每个除数 k。 b 的阶数为 min{phi(p) / k} = min{(p-1)/k}。
在Marsaglia的文章“论Pi的随机性和其他十进制展开”(http://interstat.statjournals.net/YEAR/2005/articles/0510005.pdf)中,有a、b和r的一些值。未饱的经期吃东西也很有用(见文章)。
Base b=2^32 没有完整的句点,但它返回 0 到 2^32-1 之间的整数。 Base b=2^32-1 无法返回无偏 32 位整数(它永远不会返回数字 2^31-1 = 4294967295)。
b is a primitive root when its order is p-1, so b^k can assume every value from 1 to p-1, depending on value of k.
The order of an element is the minimum s with b^s=1 (mod p).
b is a primitive root if, and only if, b^(phi(p)/k) != 1 (!= means different) for every k divisor of phi(p), and phi(p) = (p-1) is the Euler's totient function (http://en.wikipedia.org/wiki/Euler%27s_totient_function).
In your example:
- phi(p) = a*b^r = p - 1.
- Divisors of a are {1, 2, 3, 31, 23091217, 4294966362}.
- Divisors of b are {1, 3, 5, 17, 257, 65537, 4294967295}.
So, (p-1) = 2*(3^33)*(5^32)*(17^32)*31*(257^32)*(65537^32)*23091217.
p-1 has 322,570,512 divisors (http://en.wikipedia.org/wiki/Divisor_function)
With modular exponentiation, it is possible to see that
b^((p-1)/3) = 1 (mod p)
so the order of b is different of p-1.
It is better choose numbers a and b with few divisors, then p-1 also will have few divisors, and it will be easy to calculate (phi(p) / k) for every divisor k. Order of b will be min{phi(p) / k} = min{(p-1)/k}.
In Marsaglia's article "On the randomness of Pi and other decimal expansions" (http://interstat.statjournals.net/YEAR/2005/articles/0510005.pdf), there are some values of a, b and r. Periods that are not full ate usefull too (see article).
Base b=2^32 doesn't have full period, but it returns integers from 0 to 2^32-1. Base b=2^32-1 can't return unbiased 32 bit integers (it will never return number 2^31-1 = 4294967295).
我误解了获得完整句点所需的条件:
b
也必须是p
的原根,我认为这里的情况并非如此(老实说,我没有数学背景,甚至无法开始理解什么是原根)。如果有完整的句点,则句点将为a*b^r
。据我所知,不可能(或者至少很难)知道否则该周期会是什么样(坦率地说,它没有用,因为实际上需要一个完整的周期)。资料来源:现代应用统计方法杂志
I've misunderstood what is required to get a full period:
b
must also be a primitive root ofp
, which I don't think is the case here (to be honest, I don't have the math background to even begin to understand what a primitive root is). If there is a full period, the period would bea*b^r
. As far as I can tell, it's impossible (or at least very difficult) to tell what the period would be otherwise (and quite frankly, it's not useful because in practice a full period is desired).Source: Journal Of Modern Applied Statistical Methods