public int Get(int maxValue) { int result; // For dice whose weights change, a number has to be requested each roll. // For others, rolls are cached for efficiency if (_lastMax != maxValue || _lastMax == 0) { result = _client.GenerateIntegersAsync(1, 0, maxValue - 1, true).Result.Random.Data[0]; } else if (_cache == null || _index == _cacheSize) { _cache = _client.GenerateIntegersAsync(_cacheSize, 0, maxValue - 1, true).Result.Random.Data; _index = 0; result = _cache[_index++]; } else { result = _cache[_index++]; } _lastMax = maxValue; return(result); }
/// <summary> /// Get an array of random ints. /// </summary> /// <param name="digitCount">How many digits long each number will be.</param> /// <param name="count">How many numbers you want to generate.</param> /// <returns></returns> public static int[] GetInt(int digitCount, int count) { var result = myClient.GenerateIntegersAsync(count, (int)System.Math.Pow(10, digitCount), (int)(System.Math.Pow(10, digitCount) * 9), false); return(result.Result.Random.Data.ToArray()); }