r/rust•
pitdicker

Help add wasm-bindgen support to Rand

If you like to experiment with wasm-bindgen, some help to add proper support for it in the Rand crate would be great!

A description of the issue is in https://github.com/rust-lang-nursery/rand/issues/478#issuecomment-392506170. Currently we only support wasm-unknown-unknown via stdweb, and it would be nice to have a similar implementation with wasm-bindgen.

Posted May 28, 2018, 7:40 PM UTC

225
memoryruins•

An implementation exists for thread_rng's functionality: https://github.com/alexcrichton/wbg-rand

3
pitdickerOPrand•

Good link, didn't know it existed (but could have assumed). I should point out that it is using Math.random for seeding, which is not secure. What Rand wants to use, and already uses with the stdweb feature, are Crypto.getRandomValues in browsers and crypto.randomBytes in Node.js.

2
quininer•

I want to implement it, but I don't know how to make wasm-bindgen work for browsers and nodejs at same time.

3
pitdickerOPrand•

Nice, thank you!

I can help on the Rand part, but not much on wasm-bindgen... The current stdweb implementation feature-detects what is available, https://github.com/rust-lang-nursery/rand/blob/0.5.0/src/rngs/os.rs#L696. Could this do something similar, or do you mean there is another problem?

2
quininer•

wasm-bindgen does not support dynamic feature-detects, I think wbg-rand still uses Math.random for the same reason.

2