C++ || Snippet – Custom “Shuffle” Function For Arrays

Print Friendly, PDF & Email

The following is a custom “Shuffle” function which shuffles the contents of an array. This function rearranges each item within the array by swapping the value of a given item with that of some other randomly selected item.

The code demonstrated on this page is different from the STL random_shuffle function in that this implementation is meant to work mainly on standard arrays.

This implementation revolves around using a series of void pointers.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output

Leave a Reply