Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(random)!: add random functions rand and getSeed. seedRand no longer returns function and accepts a number #396

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

straker
Copy link
Owner

@straker straker commented Apr 10, 2024

Random implementation based off Python random module

  • Moved randInt and seedRand to own file, added rand and getSeed functions
  • seedRand no longer returns rand as a function but instead just modifies the seed
  • seedRand accepts a number (or no parameter and defaults to current time)
  • updated the seedRand string hash function from xfnv1a to MurmurHash3 to reuse Math.iml for slightly better compression
  • randInt accepts a function as 3rd parameter which can be used to pass a function that can bias the random number
  • randInt uses rand by default instead of Math.random so is affected by seeding the PRNG
  • updated the PRNG to use SplitMix32 algorithm instead of LCG (Lehmer RNG) as LCG is not considered a good PRNG

Closes #379
Closes #378
Closes #377
Closes #374

@straker straker merged commit a7157fd into main Apr 12, 2024
9 checks passed
@straker straker deleted the random branch April 12, 2024 14:41
@sylfel
Copy link
Contributor

sylfel commented Apr 12, 2024

Nice job !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants