public static SerializableRandom CreateNew(int seed) { var rand = new SerializableRandom(); int ii; int mj, mk; int subtraction = (seed == Int32.MinValue) ? Int32.MaxValue : Math.Abs(seed); mj = MSEED - subtraction; rand.seedArray[55] = mj; mk = 1; for (int i = 1; i < 55; i++) { ii = (21 * i) % 55; rand.seedArray[ii] = mk; mk = mj - mk; if (mk < 0) { mk += MBIG; } mj = rand.seedArray[ii]; } for (int k = 1; k < 5; k++) { for (int i = 1; i < 56; i++) { rand.seedArray[i] -= rand.seedArray[1 + (i + 30) % 55]; if (rand.seedArray[i] < 0) { rand.seedArray[i] += MBIG; } } } rand.inext = 0; rand.inextp = 21; return(rand); }
/// <summary> /// Creates a new QuantileEstimator. /// </summary> /// <param name="maximumError">The allowed error in the return value of GetProbLessThan. Must be greater than 0 and less than 1. As a rule of thumb, set this to the reciprocal of the number of desired quantiles.</param> public QuantileEstimator(double maximumError) { if (maximumError <= 0) { throw new ArgumentOutOfRangeException(nameof(maximumError), "maximumError <= 0"); } if (maximumError >= 1) { throw new ArgumentOutOfRangeException(nameof(maximumError), "maximumError >= 1"); } this.MaximumError = maximumError; // maxError = 0.05 gives bufferCount = 6, bufferLength = 46 double invError = 1 / maximumError; int bufferCount = 1 + Math.Max(1, (int)Math.Ceiling(Math.Log(invError, 2))); if (bufferCount < 2) { throw new Exception("bufferCount < 2"); } buffers = new double[bufferCount][]; countInBuffer = new int[bufferCount]; rand = SerializableRandom.CreateNew(Rand.Int()); }
/// <summary> /// Sets the seed used for random number generation. /// </summary> /// <param name="seed">Specify the seed to use for random number generation.</param> public void SetRandomSeed(int seed) => rand = SerializableRandom.CreateNew(seed);