PrimeSearch question


    • PrimeSearch question

      Hey, I had a use for your PrimeSearch class the other day, to randomly shuffle a set of objects (my previous implementation, which has existed for probably 7 or so years, just looped n*3 times, picking a random pair and swapping them... it worked alright, but while reviving this code recently, I decided it was time to update it). I use it to basically build a stack of my shuffled elements, and then pop off each one as needed. And I noticed something... the first element (last in the PrimeSearch iteration) was always the same, element 0 from my original set. Thinking about this, I think it makes sense. The initial conditions for PrimeSearch have currentPosition = 0, some random step size, etc. the first call to GetNext advances currentPosition to its first step, essentially a random element) and returns that. Continues until searches reaches the prime number for the set, at which point it has made a full cycle through the data, bringing it back to the starting point, index 0.

      I've fixed this in my code, by simply starting currentPosition at a random location in the set.

      Does this sound about right, or did I miss something here?