prime function

int prime({
  1. int? max,
})

Return a random prime number, optionally between 1 and max.

Args: max (int): The maximum number to generate a prime number from.

Returns: A random prime number.

Implementation

int prime({int? max}) {
  late List<int> primeNumbers;
  primeNumbers = _getPrimeNumbers(1000000000);
  if (max != null) {
    primeNumbers = _getPrimeNumbers(max);
    return primeNumbers[Random().nextInt(primeNumbers.length)];
  }
  return primeNumbers[Random().nextInt(primeNumbers.length)];
}