1. The "industry standard" shuffle algorithm in Euphoria
- Posted by "Boehme, Gabriel" <gboehme at POSTOFFICE.MUSICLAND.COM> Dec 07, 1999
- 343 views
Back on November 30th/December 1st (depending on your global location), in "Re: Help With My Game of Black Jack", Jiri Babor posted a shuffle() algorithm, ending his post with this rather enigmatic paragraph: >Btw, for very obscure theoretical reasons, this is *not* the best >possible shuffle, but it is still far better than what you can get by >hand. This comment got me thinking -- what *is* the "best possible" shuffle? To make a long story short, I hunted around on the internet, found some code for a "uniformly random" shuffle, converted it to Euphoria, merged it into Jiri's code, and sent the result to Jiri for his opinion. Following some additional enlightenment from Jiri, I now present the "industry standard" shuffle algorithm to the list as a generic Euphoria routine: global function shuffle(sequence s) -- randomly shuffle the elements of a sequence -- written by Gabriel Boehme -- based Jiri Babor's Euphoria interpretation of the "uniformly random" -- 1963 shuffle algorithm written by L.E. Moses and R.V. Oakford integer r object temp for i = length(s) to 2 by -1 do r = rand(i) temp = s[r] s[r] = s[i] s[i] = temp end for return s end function Hep yadda, Gabriel Boehme ---------- The unconscious democracy of America is a very fine thing. It is a true and deep and instinctive assumption of the equality of citizens, which even voting and elections have not destroyed. G.K. Chesterton ----------