How to use current time in seed number of ELM random

Random seed in Elm programming. If I use fixed seed I will get same random number. How can I use current time in seed number? I am using Elm 0.19.

Random.initialSeed <currentTime>

So - how to get current time or start time to ?

Upvotes: 3

Views: 77

Answers (1)

bdukes
bdukes

Reputation: 155935

You can use Time.now to get a Task which can produce the current time, or Time.every to subscribe to time updates.

However, if you're just trying to avoid having your random values be predictable, you will want to use Random.generate, which produces a Cmd which will trigger a message with the generated value. This prevents you from having to deal with Seed values.

Upvotes: 5

Related Questions