nextIntsUnique method

Map<int, int> nextIntsUnique(
  1. int minValue,
  2. int maxValue,
  3. int size
)

Returns a Map of unique integers of size with random integer inclusive to minValue exclusive to maxValue.

Implementation

Map<int, int> nextIntsUnique(int minValue, int maxValue, int size) {
  if (minValue > maxValue) {
    throw ArgumentError("Min value is greater than max value.");
  }

  if (size > (maxValue - minValue)) {
    throw ArgumentError("size less then maxValue-minValue");
  }

  Map<int, int> intMap = <int, int>{};
  for (int i = 1; i <= size; i++) {
    bool unique = false;
    while (unique != true) {
      int v = nextFromRange(minValue, maxValue);
      if (!intMap.containsValue(v) && v >= minValue && v <= maxValue) {
        intMap[i] = v;
        unique = true;
      }
    }
  }

  return intMap;
}