+Karl G Posted August 27, 2021 Share Posted August 27, 2021 I'm trying to figure out a good 8-bit shuffling algorithm. In this case, it's for a 7800Basic project, but the strategy would likely be the same regardless of language, or even 8-bit platform. The classic way to randomize a finite set of objects like cards would be to generate a random number between 0 and (#items - 1), then place the chosen item into a new list. The original list would be reduced by one, a new random number is generated for the smaller range, etc, continuing until all of the items from the original list have been selected and placed in the new list. The problem with this approach is that I don't know a good, easy way to generate random values for arbitrary number ranges. For powers of two it is easy, but what about generating numbers between 0-2 or 0-4, etc? Does anyone have a suggestion either for a better method for shuffling items like this, or for a decent way to generate random numbers for odd number ranges like this? 1 Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.