I have created a method that shuffles an array of integers between 0 to 9 to make a secure key pad for a page in my website. I have made it like:
int[] array = new int[10] {0,1,2,3,4,5,6,7,8,9};
List<int> numbs = new list<int>();
Random r = new Random();
for (int i = 0; i < array.Lenght;i++) {
Boolean b = true;
while (b){
if (i == r.Next(10)){
numbs.Add(array[i]);
b = false;
}
}
}
I know that this code has a very poor performance because the Random must generate a random number again and again and I don't know how many times it should run to generate a value which is equal to i. So, I wanna know what the best way to randomize the int array is.