What is the correct way of initializing an elm application

后端 未结 4 1029
有刺的猬
有刺的猬 2020-12-31 02:46

The documentation for Elm\'s Random module states:

A good way to get an unexpected seed is to use the current time. http://package.elm-

4条回答
  •  北海茫月
    2020-12-31 03:41

    If you are using the StartApp then you'll need to use a custom HTML file with

    
    

    Then to use the startTime as a seed:

    startTimeSeed : Seed
    startTimeSeed = Random.initialSeed <| round startTime
    
    app =
      StartApp.start
        { init = (init startTimeSeed, Effects.none)
        , update = update
        , view = view
        , inputs = []
        }
    

    And then in the code you'll be doing something like

    init : Seed -> List Int
    init seed = fst <| Random.generate intList seed
    

    where, for example:

    intList : Random.Generator (List Int)
    intList =
        Random.list 5 (Random.int 0 100)
    

提交回复
热议问题