Ejemplo n.º 1
0
        /// <summary>
        /// Creates a light weight PRNG from a Pooled Generator.
        /// This will wait until the Pooled Generator has created its first seed.
        /// </summary>
        public static Task <IRandomNumberGenerator> CreateCypherBasedGeneratorAsync(this PooledEntropyCprngGenerator pooledRng)
        {
            if (pooledRng == null)
            {
                throw new ArgumentNullException(nameof(pooledRng));
            }

            if (pooledRng.ReseedCount > 0)
            {
                return(Task.FromResult(pooledRng.CreateCypherBasedGenerator()));
            }
            return(WaitAndGet(pooledRng));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a light weight PRNG from a Pooled Generator.
        /// If the Pooled Generator has not created its first seed, this will use the system crypto random to derive a seed.
        /// </summary>
        public static IRandomNumberGenerator CreateCypherBasedGeneratorOrUninitialised(this PooledEntropyCprngGenerator pooledRng)
        {
            if (pooledRng == null)
            {
                throw new ArgumentNullException(nameof(pooledRng));
            }

            if (pooledRng.ReseedCount > 0)
            {
                return(pooledRng.CreateCypherBasedGenerator());
            }
            else
            {
                return(CypherBasedPrngGenerator.CreateWithSystemCrngKey());
            }
        }
Ejemplo n.º 3
0
        private static async Task <IRandomNumberGenerator> WaitAndGet(PooledEntropyCprngGenerator pooledRng)
        {
            await pooledRng.StartAndWaitForFirstSeed();

            return(pooledRng.CreateCypherBasedGenerator());
        }