예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }