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

Using a self-seeded RNG on wasm32-unknown-unknown #1249

Closed
golddranks opened this issue Aug 12, 2022 · 5 comments
Closed

Using a self-seeded RNG on wasm32-unknown-unknown #1249

golddranks opened this issue Aug 12, 2022 · 5 comments

Comments

@golddranks
Copy link
Contributor

Compile issue

Problem: There should be a way to use rand without system/environment dependencies.

Quick solution: Roll my own algorithm with multiplications, modulos and bitshifts. (It did the job but not too well.)

Details: As the README says, "The WASM target wasm32-unknown-unknown is not automatically supported". However, for things like simulation purposes, self-seeded RNGs are warranted, and as the rust-random project has a bunch of well-vetted, well-documented random algorithms plus a lot of supporting APIs, it would be great if there was a well-documented way to use them on wasm32-unknown-unknown and in other context that can't assume anything about the environment. Currently the documentation assumes that you want to get system-seeded random numbers with getrandom, which isn't necessarily true.

@golddranks
Copy link
Contributor Author

Note: If this is only a documentation problem, I'm happy to help fixing that. If it needs larger refactorings, let's see what we can do.

@dhardy
Copy link
Member

dhardy commented Aug 12, 2022

It's just a doc issue; it works fine (just disable default features). Here I used small_rng but you can use any RNG crate.
https://gist.github.com/dhardy/9ac6b0939ce8ff509996590f0835b4b1

@golddranks
Copy link
Contributor Author

I tried to use small_rng also, but with no success. I'll try to reproduce my setup later this weekend, if not just to further my own understanding what goes wrong.

@golddranks
Copy link
Contributor Author

Sorry, missed about disabling the default features; I was a bit hurry yesterday, so sorry about the noise!

@golddranks
Copy link
Contributor Author

Thanks, closing this!

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