Is this C implementation of Fisher-Yates shuffle correct? -
There is a single implementation of Fisher-Yets that I want to use in a deck-shifting routine. Am I doing it correctly (n = length of the array)? Note: To make a makeup-loop for modulo bias (see) it adds up the process slightly upwards and eliminating it if you do not care about low-bit prejudices. It is possible. J, TMP, Upper_bound; Srand (time (zero)); For (i = n - 1; i> gt; i--) {upper_bound = RAND_MAX - ((RAND_MAX% (i + 1)) + 1); Do {j = rand (%)% (i + 1); } While (h & gt; upper_bound); Tmp = array [ja]; Array [j] = array [i]; Array [ii] = tmp; First of all, you should remove the code to generate a random number, which is Be distributed evenly between a 0 (inclusive) and n (exclusive) for a separate function. It's a good job of the job you need elsewhere. Second, I do not call the srand inside the shuffle function, depending on the random number generator the caller will start this way A deck can shuffle more than once in the bar. Third, you have to g...