sample method Null safety

  1. @override
int sample(
  1. {Random? random}
)
override

Generates a random sample.

Example

import 'package:calc/calc.dart';

void main() {
  final distribution = NormalDistribution(mean=0.0, variance:1.0);
  final sample = distribution.sample();
}

Implementation

@override
int sample({Random? random}) {
  var sum = 0;
  while (true) {
    random ??= Random();
    if (random.nextDouble() > p) {
      return sum;
    }
    sum++;
  }
}