Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/ObjectPools/Random/SeededRandomPool.cs @ 15273

Last change on this file since 15273 was 15273, checked in by pkimmesw, 7 years ago

#2665 Started Plush Encoding, Added Zero Error Individual Count Analyzer

File size: 912 bytes
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random {
2  using System;
3
4  using HeuristicLab.Core;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
6  using HeuristicLab.Random;
7
8  public class SeededRandomPool {
9    public int Seed;
10    protected readonly ObjectPool<IRandom> Pool;
11
12    public SeededRandomPool() : this(new Random().Next()) { }
13
14    public SeededRandomPool(int seed) : this(seed, () => new MersenneTwister()) { }
15
16    public SeededRandomPool(int seed, Func<IRandom> randomCreator) {
17      Seed = seed;
18      Pool = new ObjectPool<IRandom>(randomCreator);
19    }
20
21    public IRandom ResetAndAllocate() {
22      var random = Pool.Allocate();
23      random.Reset(Seed);
24
25      return random;
26    }
27
28    public void Free(IRandom random) {
29      Pool.Free(random);
30    }
31
32    public void Clear() {
33      Pool.Clear();
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.