public void GetFirstGreaterTest() { Assert.AreEqual(3, PrimeNumberGenerator.GetFirstGreater(2)); Assert.AreEqual(5, PrimeNumberGenerator.GetFirstGreater(4)); Assert.AreEqual(7, PrimeNumberGenerator.GetFirstGreater(5)); Assert.AreEqual(11, PrimeNumberGenerator.GetFirstGreater(8)); Assert.AreEqual(7, PrimeNumberGenerator.GetFirstGreater(5)); Assert.AreEqual(23, PrimeNumberGenerator.GetFirstGreater(22)); Assert.AreEqual(53, PrimeNumberGenerator.GetFirstGreater(52)); Assert.AreEqual(29, PrimeNumberGenerator.GetFirstGreater(25)); }
public static HashFunction Generate(int range) { long longPrime = PrimeNumberGenerator.GetFirstGreater(range); if (longPrime > int.MaxValue) { throw new RangeTooBigException(); } int prime = Convert.ToInt32(longPrime); int a = _randomGenerator.Next(1, prime - 1); int b = _randomGenerator.Next(0, prime - 1); return(new HashFunction(prime, range, a, b)); }