0
在C++中,我尝试对两个无符号整型变量使用模运算符,如Marsaglia乘以进位算法。 结果似乎正确,但我不确定模数的局限性。modulo with unsigned int
m_upperBits = (36969 * (m_upperBits & 65535) + (m_upperBits >> 16))<<16;
m_lowerBits = 18000 * (m_lowerBits & 65535) + (m_lowerBits >> 16);
unsigned int sum = m_upperBits + m_lowerBits; /* 32-bit result */
unsigned int mod = (max-min+1);
int result=min+sum%mod;
'usigned int'不保证有正好32位。顺便说一句,有什么问题? – JohnB 2015-02-07 11:36:37
我不确定你不确定 – 2015-02-07 11:36:39
什么是“模数的限制”? – harold 2015-02-07 11:45:22