PublicBlumBlumShub::PublicBlumBlumShub(const Integer &n, const Integer &seed) : modn(n), maxBits(BitPrecision(n.BitCount())-1) { current = modn.Square(modn.Square(seed)); bitsLeft = maxBits; }
unsigned int PolynomialMod2::BitCount() const { unsigned wordCount = WordCount(); if (wordCount) return (wordCount-1)*WORD_BITS + BitPrecision(reg[wordCount-1]); else return 0; }
/** * Get the number of bits required to represent this RInteger. * * @return The size of the integer in bits. * */ EXPORT_C TUint TInteger::BitCount() const { TUint wordCount = WordCount(); if(wordCount) { return (wordCount-1)*WORD_BITS + BitPrecision(Ptr()[wordCount-1]); } else { return 0; } }
word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max) { const word32 range = max-min; const unsigned int maxBits = BitPrecision(range); word32 value; do { GenerateBlock((byte *)&value, sizeof(value)); value = Crop(value, maxBits); } while (value > range); return value+min; }
word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max) { word32 range = max-min; const int maxBytes = BytePrecision(range); const int maxBits = BitPrecision(range); word32 value; do { value = 0; for (int i=0; i<maxBytes; i++) value = (value << 8) | GenerateByte(); value = Crop(value, maxBits); } while (value > range); return value+min; }