QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads

 Return to Index  

Notes on the modified shuffle sort:

April 11 2008 at 11:37 AM
Solitaire  (Login Solitaire1)

Response to Variation of Shuffle Sort algorithm


The advantages of a shortened FOR block for the number of shuffle repetitions is negligible unless you have a range of several thousand and only a few selections. Suppose you suddenly have one more "prize" to award to a random winner? Then you will need to add something like this on to the code (using an IF block if one more pick is required):

picks = picks + 1
index = INT(RND * range) + 1
SWAP numbers(indx), numbers(picks)

or you could complete the remaining selections by including another FOR loop going to the range:

FOR x = picks + 1 TO range
   'same code as in above post

or having the user enter the number of additional selections needed:

FOR x = picks + 1 TO picks + addon
'same code as in above post

It may make more sense to simply include a larger value to "picks" in the first place rather than resorting to those patches. For a small range, I would shuffle the entire range. For a very large range, I would add on a proportionate percentage of extra "picks" to the shuffle sort FOR loop. (That would require an IF block. You would also need to select an arbitrary percentage to use and come up with the formula for applying it.)

This message has been edited by Solitaire1 on Apr 11, 2008 11:23 PM

 Respond to this message   

 Copyright © 1999-2018 Network54. All rights reserved.   Terms of Use   Privacy Statement