using System; using HeuristicLab.Core; using HeuristicLab.Random; namespace HeuristicLab.Problems.ProgramSynthesis { public class SeededRandomPool { public int Seed; protected readonly ObjectPool Pool; public SeededRandomPool() : this(new System.Random().Next()) { } public SeededRandomPool(int seed) : this(seed, () => new FastRandom()) { } public SeededRandomPool(int seed, Func randomCreator) { Seed = seed; Pool = new ObjectPool(randomCreator); } public IRandom ResetAndAllocate() { var random = Pool.Allocate(); random.Reset(Seed); return random; } public void Free(IRandom random) { Pool.Free(random); } public void Clear() { Pool.Clear(); } } }