/// <summary> /// Returns a delegate that is able to generate random /// <c>int</c> numbers in an arbitrary range. /// </summary> /// <param name="byteGenerator">A delegate that fills the passed byte array with random values.</param> /// <returns> /// A delegate that wraps around the <paramref name="byteGenerator"/> /// to produce random <c>int</c> values in the range supplied as its argument. /// </returns> public static BoundedGenerator <int> CreateNextIntBounded(ByteGenerator byteGenerator) { UpperBoundedGenerator <long> nextLongUpperBounded = CreateNextLongUpperBounded(byteGenerator); return((int minValue, int maxValue) => minValue + (int)nextLongUpperBounded((long)maxValue - minValue)); }
/// <summary> /// Initializes an instance of <see cref="RandomCryptographic"/> /// with a single instance of cryptographically strong <see cref="RandomNumberGenerator"/>. /// </summary> /// <param name="gen"> /// An instance of cryptographically strong <see cref="RandomNumberGenerator"/>. /// If <c>null</c>, an instance built from <see cref="RNGCryptoServiceProvider.Create"/> will be used. /// </param> public RandomCryptographic(RandomNumberGenerator gen = null) { if (gen == null) { gen = RNGCryptoServiceProvider.Create(); } this.gen = gen; // initialize methods this.___nextIntB = RandomFunctionalityExtensions.CreateNextIntBounded(this.gen.GetBytes); this.___nextIntNB = RandomFunctionalityExtensions.CreateNextIntUnbounded(this.gen.GetBytes); this.___nextIntUB = RandomFunctionalityExtensions.CreateNextIntUpperBounded(this.gen.GetBytes); this.___nextLongB = RandomFunctionalityExtensions.CreateNextLongBounded(this.gen.GetBytes); this.___nextLongNB = RandomFunctionalityExtensions.CreateNextLongUnbounded(this.gen.GetBytes); this.___nextLongUB = RandomFunctionalityExtensions.CreateNextLongUpperBounded(this.gen.GetBytes); this.___nextUIntB = RandomFunctionalityExtensions.CreateNextUIntBounded(this.gen.GetBytes); this.___nextUIntNB = RandomFunctionalityExtensions.CreateNextUIntUnbounded(this.gen.GetBytes); this.___nextUIntUB = RandomFunctionalityExtensions.CreateNextUIntUpperBounded(this.gen.GetBytes); this.___nextULongB = RandomFunctionalityExtensions.CreateNextULongBounded(this.gen.GetBytes); this.___nextULongNB = RandomFunctionalityExtensions.CreateNextULongUnbounded(this.gen.GetBytes); this.___nextULongUB = RandomFunctionalityExtensions.CreateNextULongUpperBounded(this.gen.GetBytes); }
private void ___generator_delegate_init() { genLongBounded = RandomFunctionalityExtensions.CreateNextLongBounded(rnd.NextBytes); genLongUpperBounded = RandomFunctionalityExtensions.CreateNextLongUpperBounded(rnd.NextBytes); genLongUnbounded = RandomFunctionalityExtensions.CreateNextLongUnbounded(rnd.NextBytes); genULongBounded = RandomFunctionalityExtensions.CreateNextULongBounded(rnd.NextBytes); genULongUpperBounded = RandomFunctionalityExtensions.CreateNextULongUpperBounded(rnd.NextBytes); genULongUnbounded = RandomFunctionalityExtensions.CreateNextULongUnbounded(rnd.NextBytes); }