-
-
Save mischief/647c0a9c6d86b2aa43b2bb9dc7197ac0 to your computer and use it in GitHub Desktop.
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
| /* fisher-yates shuffle */ | |
| void | |
| shuffle(void *base, long nel, long width) | |
| { | |
| unsigned char *b, *swap1, *swap2; | |
| long i, j, k; | |
| b = base; | |
| for(i = nel - 1; i > 0; i--){ | |
| j = nrand(i); | |
| swap1 = &b[i*width]; | |
| swap2 = &b[j*width]; | |
| for(k = 0; k < width; k++){ | |
| *swap1 ^= *swap2; | |
| *swap2 ^= *swap1; | |
| *swap1++ ^= *swap2++; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment