- :
public static Random Rnd { get; set; }
, , , , , Divisor:
if(Rnd == null)
{
Rnd = new Random();
}
int Min = p;
int Max = q;
if(Min > Max)
{
int Temp = Max;
Max = Min;
Min = Temp;
}
int Divisor = n;
int NextRandom = Rnd.Next(Min, Max + 1);
while(NextRandom % Divisor != 0)
{
NextRandom = Rnd.Next(Min, Max + 1);
}
%. .
, NextRandom% Divisor 0, Divisor NextRandom.
:
public static int GetRandomMultiple(int divisor, int min, int max)
{
if (Rnd == null)
{
Rnd = new Random();
}
if(min > max)
{
int Temp = max;
max = min;
min = Temp;
}
int NextRandom = Rnd.Next(min, max + 1);
while (NextRandom % divisor != 0)
{
NextRandom = Rnd.Next(min, max + 1);
}
return NextRandom;
}
:
int Number = GetRandomMultiple(n, p, q);
. Max - "". , .Net. Max , Min..Max - 1. .