Generate Random Numbers excluding a certain range of values- C#

Rather than throwing out numbers that are in the range 70000-71000, generate a number from 10000-89999 and if it’s greater than 70000 then add 1000 to it. For example:

var num = rnd.Next(10000, 90000);
if (num > 70000)
{
    num += 1000;
}

You’re just mapping the numbers in the range 70001-89999 to 71001-99999.

Leave a Comment