samedi 1 juin 2019

C# Am I doing "Bays & Durham Randomization by Shuffling" correctly?

I tried to improvise a random number generator by using the "Bays & Durham Randomization by Shuffling" algorithm. I followed a tutorial online and made this code:

 public int[] GenerateRandomSequence_Improved(int n, int min, int max)
 {
       int[] seq = new int[n];
       for(int i = 0; i < n; i++)
       {
           int rand = GenerateNextRandomNumber(min, max);

           rand = min + rand % (max + 1 - min);
           seq[i] = rand;
       }
       return seq;
 }

I wanna know if I did it correctly or not..

EDIT: This is the code for the GenerateNextRandomNumber method

public int GenerateNextRandomNumber(int min, int max)
{
       return cSharpRNG.Next(min,max);
}




Aucun commentaire:

Enregistrer un commentaire