Create an algorithm


#1

Write an algorithm :

Given an array of integers,in-place shuffle it,the algorithm should produce an unbiased permutation i.e. every permutation is equally likely


#2

void swapElement(int* a,int i,int j){
int x=*(a+i);
*(a+i)= *(a+j);
*(a+j)= x;
}
void rand_arr(int *arr,int n)
{
for(int i=n-1;i>0;i–){
swapElement(arr,i,rand()%(i+1));
}
}

This algorithm selects the last element of the array, swaps it with a random element of the array, and then repeat the same process with the array without the last element.