public void GenerateRandomInteger() { RandomIntegerGenerator randomNumberGenerator = new RandomIntegerGenerator(); int randomNumber = randomNumberGenerator.GenerateRandomInteger(-100, 100); Assert.True(randomNumber >= -100); Assert.True(randomNumber <= 100); }
/// <summary> /// Tests creating a random integer generator with a particular set of lower bounds /// and an integer count /// </summary> /// <param name="lowerBound">The lower bounds (inclusive) of the integers to be generated</param> /// <param name="upperBound">The upper bounds (inclusive) of the integers to be generated</param> /// <param name="count">The number of integers to be generated</param> private void TestRandomIntegerGenerator(int lowerBound, int upperBound, int count) { Assert.That(count, Is.GreaterThanOrEqualTo(0)); Assert.That(lowerBound, Is.AtMost(upperBound)); IRandomIntegerGenerator randomIntGenerator = new RandomIntegerGenerator(); //Create the random integer generator IEnumerable <int> randomIntegers = randomIntGenerator.CreateIntegerGenerator(lowerBound, upperBound, count); //Iterate over the random integers, verifying that there are the correct number of integers //and that they all fall within the specified bounds int integerCount = 0; foreach (int randomInt in randomIntegers) { //Verify that the random integer is within the specified bounds Assert.That(randomInt, Is.AtLeast(lowerBound)); Assert.That(randomInt, Is.AtMost(upperBound)); integerCount++; } //Verify that the correct number of integers were generated Assert.That(integerCount, Is.EqualTo(count)); }
public void GenerateRandomInteger() { var randomNumberGenerator = new RandomIntegerGenerator(); var randomNumber = randomNumberGenerator.GenerateRandomInteger(-100, 100); Assert.True(randomNumber >= -100); Assert.True(randomNumber <= 100); }
public int[] RandomIntArray(long length, int min, int max) { var arr = new int[length]; for (var i = 0; i < arr.Length; i++) { arr[i] = new RandomIntegerGenerator().GenerateValue(min, max); } return(arr); }
/// <summary> /// Author: Brian Sabotta /// Created: 10/30/2019 /// Notes: Get a random coin, based on how much change remains to be paid. /// We want to avoid trying to pick a coin that is higher than the remaining amount. /// </summary> /// <param name="currentChangeAmount">Current amount of change to be paid.</param> /// <returns>Returns a Coin object representing a random coin denomination.</returns> private static Coin GetRandomCoin(int currentChangeAmount) { //Pick a random number in the valid range (current valid denominations) //Determine upper bound of random range var upperBound = GetDenominationUpperBound(currentChangeAmount); var lowerBound = 0; //Always 0, which is the lowest index in the collection var randomCoinIndex = RandomIntegerGenerator.GetRandomNumber(lowerBound, upperBound); var currentCoin = AllDenominations[randomCoinIndex]; return(currentCoin); }
public void Setup() { _generator = new RandomIntegerGenerator(TotalDataMB); }
public void Setup() { _randomDecimal = new RandomDecimalGenerator(); _randomInteger = new RandomIntegerGenerator(); _randomString = new RandomStringGenerator(); }
/* Construction/Destruction */ public BufferedStreamReader() { _randomIntStructGenerator = new RandomIntStructGenerator(StructBytesMB); _randomIntegerGenerator = new RandomIntegerGenerator(StructBytesMB); }