The PortFunnel.DevRandom module provides a billstclair/elm-port-funnel funnel to generate cryptographically-secure random numbers. It does this with JavaScript code that calls window.crypto.getRandomValues().
There is a simulator that uses the standard Elm Random module, which is NOT cryptographically secure. See example/Diceware.elm for how to use it.
See the example readme for instructions on creating the ports and using the included JavaScript code.
A MessageResponse encapsulates a message.
RandomBytesResponse wraps a list of integers and whether their generation was cryptographically secure.
RandomIntResponse wraps an integer and whether its generation was cryptographically secure.
Our internal state.
This module's state is only used by the simulator. If you don't save it, the simulator will always use the same random seed.
PortFunnel.FunnelSpecThe name of this funnel: "DevRandom".
Our module descriptor.
Responsible for sending a CmdResponse back through the port.
This funnel doesn't initiate any sends, so this function always returns Cmd.none.
StateThe initial state. Encapsulates a Random.Seed.
The arg is passed to Random.initialSeed. This is used only by the simulator,
so if you're using the JS code for real random numbers, passing 0 here is fine.
Message out the Cmd PortConvert a Message to the same JSON string that gets sent
over the wire to the JS code.
Make a simulated Cmd port.
The
GenerateBytesmessage requests a list of random bytes of the given size.The
RandomBytesmessage returns those random bytes.The
GenerateIntmessage requests a random integer >= 0 and < its arg.The
RandomIntmessage returns that integer.The
SimulateBytesandSimulateIntmessages are used internally by the simulator.