Added option to be deterministic

This commit is contained in:
Thorsten Sommer 2020-09-26 14:02:11 +02:00
parent 29a913843a
commit b26ba9ea90

View File

@ -55,33 +55,37 @@ namespace FastRng.Double
var ticks = now.Ticks; var ticks = now.Ticks;
this.mW = (uint) (ticks >> 16); this.mW = (uint) (ticks >> 16);
this.mZ = (uint) (ticks % 4294967296); this.mZ = (uint) (ticks % 4294967296);
this.StartProducerThreads(); this.StartProducerThreads(deterministic: false);
} }
public MultiThreadedRng(uint seedU) public MultiThreadedRng(uint seedU)
{ {
this.mW = seedU; this.mW = seedU;
this.mZ = 362436069; this.mZ = 362436069;
this.StartProducerThreads(); this.StartProducerThreads(deterministic: true);
} }
public MultiThreadedRng(uint seedU, uint seedV) public MultiThreadedRng(uint seedU, uint seedV)
{ {
this.mW = seedU; this.mW = seedU;
this.mZ = seedV; this.mZ = seedV;
this.StartProducerThreads(); this.StartProducerThreads(deterministic: true);
} }
private void StartProducerThreads() private void StartProducerThreads(bool deterministic = false)
{ {
this.producerRandomUint[0] = new Thread(() => this.RandomProducerUint(this.channelRandomUint.Writer, this.producerTokenSource.Token)) {IsBackground = true}; this.producerRandomUint[0] = new Thread(() => this.RandomProducerUint(this.channelRandomUint.Writer, this.producerTokenSource.Token)) {IsBackground = true};
this.producerRandomUint[1] = new Thread(() => this.RandomProducerUint(this.channelRandomUint.Writer, this.producerTokenSource.Token)) {IsBackground = true}; this.producerRandomUint[1] = new Thread(() => this.RandomProducerUint(this.channelRandomUint.Writer, this.producerTokenSource.Token)) {IsBackground = true};
this.producerRandomUint[0].Start(); this.producerRandomUint[0].Start();
if(!deterministic)
this.producerRandomUint[1].Start(); this.producerRandomUint[1].Start();
this.producerRandomUniformDistributedDouble[0] = new Thread(() => this.RandomProducerUniformDistributedDouble(this.channelRandomUint.Reader, channelRandomUniformDistributedDouble.Writer, this.producerTokenSource.Token)) {IsBackground = true}; this.producerRandomUniformDistributedDouble[0] = new Thread(() => this.RandomProducerUniformDistributedDouble(this.channelRandomUint.Reader, channelRandomUniformDistributedDouble.Writer, this.producerTokenSource.Token)) {IsBackground = true};
this.producerRandomUniformDistributedDouble[1] = new Thread(() => this.RandomProducerUniformDistributedDouble(this.channelRandomUint.Reader, channelRandomUniformDistributedDouble.Writer, this.producerTokenSource.Token)) {IsBackground = true}; this.producerRandomUniformDistributedDouble[1] = new Thread(() => this.RandomProducerUniformDistributedDouble(this.channelRandomUint.Reader, channelRandomUniformDistributedDouble.Writer, this.producerTokenSource.Token)) {IsBackground = true};
this.producerRandomUniformDistributedDouble[0].Start(); this.producerRandomUniformDistributedDouble[0].Start();
if(!deterministic)
this.producerRandomUniformDistributedDouble[1].Start(); this.producerRandomUniformDistributedDouble[1].Start();
} }