randomNextInt static method

int randomNextInt(
  1. int to, {
  2. int from = 0,
  3. bool contains = false,
  4. int increase = 1,
})

随机数,给定数值范围

参数

  • from 起始数值
  • to 结束数值
  • contains 是否包含结束值
  • increase 递增值

Implementation

static int randomNextInt(int to,
    {int from = 0, bool contains = false, int increase = 1}) {
  List<int> list = [];
  for (int i = from; i < (contains ? (to + 1) : to); i += increase) {
    list.add(i);
  }
  var ran = Random();
  return list.elementAt(ran.nextInt(list.length));
}