Skip to content

Instantly share code, notes, and snippets.

@coderespawn
Created May 6, 2013 11:44
Show Gist options
  • Save coderespawn/5524679 to your computer and use it in GitHub Desktop.
Save coderespawn/5524679 to your computer and use it in GitHub Desktop.
Fast PRNG in dart
class FastRandom {
int seed;
FastRandom() {
seed = new DateTime.now().millisecondsSinceEpoch & 0x7FFF;
}
int nextInt() {
seed = (214013 * seed + 2531011) & 0x7FFFFFFF;
return (seed >> 16) & 0x7FFF;
}
num nextNumRange(num low, num high) {
return low + nextNum() * (high - low);
}
num nextNum() {
return nextInt() / 0x7FFF;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment