Array Random Sorting

Status
You're currently viewing only htom's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

htom

Ars Legatus Legionis
12,590
Subscriptor
Random is hard. Knuth is good for random (he's good for lots of other topics, too!)

If you have a good random generator, the trick of assigning each card a random weight (0 .. <1) and then sorting by weight should work well.

If you want to be recursive and confusing, use quicksort backwards and inside-out on the array, doing the swaps depending on the odd/even output of sequential random integers rather than the key values; this should approximate one riffle shuffle, you'll need eight, IIRC, for good results.
 
Status
You're currently viewing only htom's posts. Click here to go back to viewing the entire thread.
Not open for further replies.