getRandomInt static method

int getRandomInt(
  1. int min,
  2. int max, {
  3. bool inclusiveMin = true,
  4. bool inclusiveMax = true,
})

获取随机整数(默认包含最大最小值)

Implementation

static int getRandomInt(int min, int max, {bool inclusiveMin = true, bool inclusiveMax = true}) {
  assert(min <= max, 'Min must be less than or equal to Max,Invalid arguments: min=$min, max=$max');
  int minVal = inclusiveMin ? min : min + 1;
  int maxVal = inclusiveMax ? max : max - 1;
  return minVal + Random.secure().nextInt(maxVal - minVal + 1);
}