Created
November 20, 2012 05:20
-
-
Save samma835/4116196 to your computer and use it in GitHub Desktop.
Fisher和Yates的洗牌算法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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