Example #1
0
        double[] y; //History of the output stream

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Instantiate a random number generator based on the parameters used to build the factory.
        /// This allows having several independent random streams running, based on the same cut-off, etc.
        /// This constructor initializes the "history" by pre-calling the stream as needed. This
        /// minimizes the effect of the initial zeroes in the history.
        /// </summary>
        /// <param name="p">The PinkRNGFactory that controls the type of stream generated</param>
        public PinkRNG(PinkRNGFactory p)
        {
            pf = p;
            x = new double[p.n];
            y = new double[p.n];
            for (int i = 0; i < p.n; i++) pinkRND(); //prime the pump, a bit (it's IIR after all!)
        }
Example #2
0
 public double Calculate(double t, int channel)
 {
     double v;
     if (gauss) v = Utilities.GaussRND();
     else if (pink)
     {
         if (!pinkRNGs.ContainsKey(channel))
         {
             if (pf == null)
             {
                 double dT = 1D / containingWindow.parameters.samplingRate;
                 pf = new PinkRNGFactory(pinkF, dT, 3);
             }
             pinkRNGs.Add(channel, new PinkRNG(pf));
         }
         PinkRNG p;
         pinkRNGs.TryGetValue(channel, out p); // no need to test, we've already done so
         v = p.pinkRND();
     }
     else v = Utilities.UniformRND();
     return Coef * Utilities.ApplyCR(v, CCoef, channel);
 }