The DevRandom module provides a way to generate cryptographically-secure random numbers. It does this by using two ports to communicate with JavaScript code that calls window.crypto.getRandomValues().
There are two ways to call the generator, depending on the Config parameter to generate. One way works in a pure Elm environment, and uses the normal Elm Random module, which is not cryptographically secure. The other way requires you to use ports to communicate with JavaScript code, most of which is provided with the example.
See the example readme for instructions on creating the ports and using the included JavaScript code.
Message wrapper for receive port of dev-random-port.js
(isSecure, bytes) -> msgIf isSecure is True, then the random number generation was cryptographically secure.
Parameter to generate that determines whether to use the Elm Random module or ports to the JavaScript code that calls window.crypto.getRandomValues().
If sendPort is not Nothing, will use the ports.
If sendPort is Nothing, and receiveMsgWrapper is not Nothing, will use the Elm Random module.
Generate a number of random bytes (integers between 0 and 255, inclusive).
generate bytes configIf config.sendPort is not Nothing, return a Cmd that sends bytes through the port. Otherwise, if config.receiveMsgWrapper is not Nothing, use it to wrap the result of Random.generate() as a message for your update function.
Signature of send port for dev-random-port.js
The
Intarg is the number of bytes (8-bit integers) to generate.