_ARRAY_SHUFFLE uses weak shuffle approach

Begonnen von vladimirsitnikov, 22. Juli 2016, 12:04:27

Vorheriges Thema - Nächstes Thema

0 Mitglieder und 1 Gast betrachten dieses Thema.

vladimirsitnikov

Here's what _ARRAY_SHUFFLE uses:
stop := UINT_TO_INT(SHR(size,2)-1);
FOR i := 0 TO stop DO
        pos := RDM2(i+pos,0,stop);
        (* swap elements *)
        temp := pt^[i];
        pt^[i] := pt^[pos];
        pt^[pos] := temp;
END_FOR;


Technically speaking, for Fisherâ€"Yates shuffle (see https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) a loop of length "size" is required, not "size/2-1".

Does it make sense to correct the shuffle so it implemets Fisher-Yates properly?