Skip to content

blacktaxi/elm-random-secure

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

elm-random-secure Build Status

Cryptographic random number generation for Elm.

A simple wrapper around the window.crypto.getRandomValues API to generate cryptographic random values in Elm.

Example

Random generation function return a Task. Depending on your use case, you might want to convert the task to an Effects or otherwise use it.

Assuming you're using start-app, in your update function:

update : Action -> Model -> (Model, Effects Action)
update action model =
  case action of
    Toss ->
      ( model
      , SecureRandom.bool -- generating a random Bool value here
          |> Task.toMaybe
          |> Task.map Catch
          |> Effects.task
      )

    Catch coin ->
      ({ model | coin = coin }, Effects.none)

TODO

  • Tests
  • Invalid argument handling

About

Generate cryptographically random values in Elm

Resources

Stars

Watchers

Forks

Packages

No packages published