I made a small random number generator program in c# that uses the discarding strategy. The problem is it returns only a sequence of the same numbers, but they have to be random. What could be the problem?
public int[] GenerateRandomwithdiscarding(int n, int min, int max)
{
int j = 0;
int[] sequence = new int[n];
for (j=0;j<n;j++)
{
int count = 0;
while(count<j)
{
int r = GenerateNextRandomNumber();
r = min + r % (max + 1 - min);
sequence[j] = r;
count++;
}
}
return sequence;
}
And the function GenerateNextRandomNumber is already created and has no problems
My GenerateRandomNumber()
looks like this (?)
public int GenerateNextRandomNumber()
{
int j = 24;
int k = 55;
int m = (int)Math.Pow(2, 32);
long seed = DateTime.Now.Millisecond;
long randomNumber = (j * seed + k) % m;
seed = randomNumber;
int finalRandom = (int)randomNumber;
return Math.Abs(finalRandom);
}