Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active November 2, 2016 21:12
Show Gist options
  • Save paulhayes/5653345dff51328719aa to your computer and use it in GitHub Desktop.
Save paulhayes/5653345dff51328719aa to your computer and use it in GitHub Desktop.
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;
}
}
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