First we can generate a list with all mutiples of 5 between 0 and 100000 (not included).
List<int> numbers = new List<int>;
for (int i = 0; i < 100000; i += 5)
{
numbers.Add(i);
}
Then you can take a number at a random position and remove it from the list so that you will get each number only once.
Random rand = new Random();
while (numbers.Count > 0)
{
int randomIndex = rand.Next(numbers.Count);
int randomNumber = numbers[randomIndex];
System.Diagnostics.Debug.Assert((randomNumer % 5) == 0);
numbers.RemoveAt(randomIndex);
DoSomethingWithRandomMultipleOf5(randomNumbr);
}
If you don't want number to be returned only once, it is even easier.
const int maxReturnedValue = 99995;
const int multipleOf = 5;
const int randLimit = (maxReturnedValue - 1) / multipleOf;
Random rand = new Random();
while (WantAnotherRandomNumber())
{
int randomNumber = rand.Next(randLimit) * multipleOf;
System.Diagnostics.Debug.Assert((randomNumer % 5) == 0);
System.Diagnostics.Debug.Assert(randomNumer >= 0);
System.Diagnostics.Debug.Assert(randomNumer <= 99995);
DoSomethingWithRandomMultipleOf5(randomNumbr);
}