Skip to content

Instantly share code, notes, and snippets.

@samma835
Created November 20, 2012 05:20
Show Gist options
  • Save samma835/4116196 to your computer and use it in GitHub Desktop.
Save samma835/4116196 to your computer and use it in GitHub Desktop.
Fisher和Yates的洗牌算法
void ShuffleArray_Fisher_Yates(char* arr, int len)
{
int i = len, j;
char temp;
if ( i == 0 ) return;
while ( --i ) {
j = rand() % (i+1);
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment