static public void Suffle_array(ref Chromosome[] array) { for (int i = 0; i < array.Length * 10; i++) { int p1 = Random_Number.GetRandomNumber(0, array.Length - 1); int p2 = Random_Number.GetRandomNumber(0, array.Length - 1); Chromosome temp = array[p1]; array[p1] = array[p2]; array[p2] = temp; } }
static public void Suffle_array(ref Chromosome[,] array) { int a = (int)array.GetLongLength(0); int b = (int)array.GetLongLength(1); for (int CN = 0; CN < array.GetLongLength(0); CN++) { for (int i = 0; i < array.GetLongLength(1) * 10; i++) { int p1 = Random_Number.GetRandomNumber(0, (int)array.GetLongLength(1) - 1); int p2 = Random_Number.GetRandomNumber(0, (int)array.GetLongLength(1) - 1); Chromosome temp = array[CN, p1]; array[CN, p1] = array[CN, p2]; array[CN, p2] = temp; } } }
public int spin() { // Create a random number between 0 and 1 and times by the total we calculated earlier. double random_number = (double)Random_Number.GetRandomNumber(0, 1000000) / 1000000; double r = random_number * total; // Binary search for efficiency. Objective is to find index of the number just above r: int index = 0; int b = c.Length - 1; while (b - index > 1) { int mid = (index + b) / 2; if (c[mid] > r) { b = mid; } else { index = mid; } } return(index); }