sampleExponentialPdf function

List<num> sampleExponentialPdf(
  1. int n,
  2. num mean,
  3. {int seed}
)

Returns a random sample of size n following an exponential distribution.

  • mean must be larger than zero,
  • seed is optional (seeds the random number generator)
  • Generator uses inversion sampling.

Implementation

List<num> sampleExponentialPdf(
  int n,
  num mean, {
  int? seed,
}) {
  if (mean <= 0) {
    throw ErrorOfType<InvalidFunctionParameter>(
        invalidState: 'mean: $mean <= 0',
        expectedState: 'mean > 0',
        message: 'Could not generate random exponential sample');
  }
  final random = Random(seed);
  return List<num>.generate(n, (_) => -mean * log(1.0 - random.nextDouble()));
}