October 8th, 2013, 1:16 pm
QuoteOriginally posted by: outrunQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: outrunExcellent acastaldo, .. that's smart allowing for i to be j, and that will indeed solve it.I have opened a post on Programming to inquire if this algo is in C++ 11. BTW is it possible to devise a test to see if the algo is 'good'?Yes, a good algorithm will generate all possible permutations of the elements with equal probability. A bad algorithm will have a bias in the probabilities. Eg when supplied with a set of elements in some initial order (like a vector) a bad algorithm might *never* return the elements in their original order. That's what the snippet with the loop to 6000 tests. In one of 6 shuffles is should leave the set of 3 elements in their original order (3 elements -> 3!=6 possible orderings of the elements)There would be other tests, too. Given an input of 1 to N, the position-weighted moments of a infinite run of permutations should have easily-calculated values. Any non-uniformity of the shuffler will resolve as statistical discrepancy between the theoretical value and the computational/empirical value of those moments.