/// <summary> /// Gets a random number provider for a given seed and pdf. /// </summary> /// <param name="pdfName">Name of PDF.</param> /// <returns> /// A random number provider. /// </returns> public IRandomNumberProvider GetRandomProvider(string pdfName = null) { string workingPdfName = null; if (pdfName == null) { if (CurrentPdfName == null) { return(_defaultRandomNumberProviderFactory.GetRandom(Seed)); } else { workingPdfName = CurrentPdfName; } } else { workingPdfName = pdfName; } if (_pdfDictionary.ContainsKey(workingPdfName)) { if (!_pdfInstancesDictionary.ContainsKey(workingPdfName)) { _pdfInstancesDictionary[workingPdfName] = _pdfDictionary[workingPdfName](); } if (!_cdfDictionary.ContainsKey(workingPdfName)) { _cdfDictionary[workingPdfName] = new Cdf(_pdfInstancesDictionary[workingPdfName], CdfPoints); } if (!_customRandomNumberProviderFactories.ContainsKey(workingPdfName)) { _customRandomNumberProviderFactories[workingPdfName] = new CustomRandomNumberProviderFactory(_cdfDictionary[workingPdfName]); } return(_customRandomNumberProviderFactories[workingPdfName].GetRandom(Seed)); } else { throw new ArgumentException("Unknown pdf", nameof(pdfName)); } }
/// <summary> /// Initializes a new instance of the <see cref="CustomRandomNumberProviderFactory"/> class. /// </summary> /// <param name="cdf">Cdf.</param> public CustomRandomNumberProviderFactory(Cdf cdf) { _cdf = cdf ?? throw new ArgumentNullException(nameof(cdf)); }
/// <summary> /// Initializes a new instance of the <see cref="CustomRandomNumberProvider"/> class. /// </summary> /// <param name="cdf">Cdf.</param> /// <param name="baseRandom">Base random provider.</param> public CustomRandomNumberProvider(Cdf cdf, IRandomDoubleProvider baseRandom) { _cdf = cdf; _baseRandom = baseRandom; }