// Algorithm from Dr Dobbs Journal, January 2000, page 113 void ShuffleCStringArray(CStringArray &a) { CString str; int dest, src, n; srand((unsigned)time(NULL)); n = a.GetSize(); for (dest = n - 1; dest > 0; dest--) { src = rand() % (dest + 1); // Swap str = a[src]; a[src] = a[dest]; a[dest] = str; } }
Programming Tips - MFC: Randomize the order (shuffle) an MFC CStringArray ?
Date: 2009oct11
Language: C/C++
Framework: MFC
Q. MFC: Randomize the order (shuffle) an MFC CStringArray ?
A. Here's a function that does it.