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

Implement a custom random number generator #35

Open
colinbdclark opened this issue May 2, 2022 · 2 comments
Open

Implement a custom random number generator #35

colinbdclark opened this issue May 2, 2022 · 2 comments

Comments

@colinbdclark
Copy link
Contributor

Currently, Signaletic uses rand() from the standard library to implement our randf() function. This works for the moment because all our target platforms provide an implementation, but it may be slower than is ideal (because on ARM, the hardware may provide faster implementations and on wasm, Emscripten's implementation likely requires a call to JavaScript to get a seed).

We should implement a very simple, fast default random number generator that allows the user to provide their own seeds, and which can support Host-provided seeding strategies.

The minimal PCG implementation or TinyMT32 are two mainstream options, while the musicdsp forum provides some very simple and fast-looking options since we don't need cryptographic rigour.

@colinbdclark
Copy link
Contributor Author

As noted in a comment in the code above sig_randf(), I think the best option for this is to implement the "quick and dirty" LCR method documented in Numerical Recipes in C.

This should be implemented as new struct that provides randf, seed, and any other necessary base functions as pointers so that alternative implementations can be provided if needed.

@amb26
Copy link

amb26 commented Jun 10, 2022

A more recent survey of LCGs with good spectral properties is in Pierre L'Ecuyer https://www.ams.org/journals/mcom/1999-68-225/S0025-5718-99-00996-5/S0025-5718-99-00996-5.pdf - I imagine you probably want the ones in the row for 2^32 -5 ?

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

No branches or pull requests

2 participants