mercredi 21 juin 2017

how to choose different random number each time

I wrote the following code to choose location from an array depending on a random number as location, but I got duplicated results!!.

How to get different random number each time in which to get different values from the array ?

Random rnd = new Random(); // to gereate random number (either 0 or 1)

 /*  Choose randomly one of cells in the topology grid to be the location of the AUV for this chromosome in the population  */

                    randomIndex = rnd.Next(0, 5); // to select random X or Y coordinates from the array of cellsCenters for the AUV random loaction in each chromosome 

                    auvChromosomeLocations[i, 0] = cellsCenters[0, randomIndex];

                    randomIndex = rnd.Next(0, 5); // to select random X or Y coordinates from the array of cellsCenters for the AUV random loaction in each chromosome 

                    auvChromosomeLocations[i, 1] = cellsCenters[0, randomIndex];




Aucun commentaire:

Enregistrer un commentaire