/// <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)); }
/// <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()); } }
private static async Task <IRandomNumberGenerator> WaitAndGet(PooledEntropyCprngGenerator pooledRng) { await pooledRng.StartAndWaitForFirstSeed(); return(pooledRng.CreateCypherBasedGenerator()); }