Last active
November 2, 2016 21:12
-
-
Save paulhayes/5653345dff51328719aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RandomShuffleSequence | |
| { | |
| public static int Shuffled(int cycleLength, int seed, int index) | |
| { | |
| int shuffleRange = cycleLength; | |
| int output = index % shuffleRange; | |
| int cycleIndex = index / cycleLength; | |
| while (output < shuffleRange) | |
| { | |
| output = (output + cycleIndex + seed) % shuffleRange; | |
| shuffleRange--; | |
| } | |
| return output; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Shuffler = function(cycleLength, seed, index){ | |
| var shuffleRange = cycleLength; | |
| var output = index % shuffleRange; | |
| var cycleIndex = index / cycleLength >> 0; | |
| while( output < shuffleRange ){ | |
| output = (output + cycleIndex + seed) % shuffleRange; | |
| shuffleRange--; | |
| } | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment