小编Joh*_*rin的帖子

榆树 - 初始奇怪行为的随机数

只需处理样本,就可以创建2个随机骰子并用按钮滚动它们.

http://guide.elm-lang.org/architecture/effects/random.html

所以我想我会将骰子创建为模块,删除滚动动作,然后让它在init上创建D6值.

所以我的代码现在如下(应该直接在elm-reactor中打开)

module Components.DiceRoller exposing (Model, Msg, init, update, view)

import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Random
import String exposing (..)

main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }



-- MODEL


type alias Model =
    { dieFace : Int
    }


init : ( Model, Cmd Msg )
init =
    ( Model 0, (Random.generate NewFace (Random.int …
Run Code Online (Sandbox Code Playgroud)

random elm

6
推荐指数
1
解决办法
381
查看次数

标签 统计

elm ×1

random ×1