Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/ObjectPools/Random/SeededRandomPool.cs @ 15692

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

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

File size: 907 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 FastRandom()) { }
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.