Domanda

I need to find a good value to feed into mkStdGen as a seed.

The first thing I'd normally do is just use the ticks since the beginning of the epoch, however, to do that I use getClockTime from System.Time, which according to hackage is deprecated, in favour of Data.Time. The latter doesn't seem to expose this functionality though.

Is there a better way to generate a seed for this value? Or should I just ignore the deprecation warning?

È stato utile?

Soluzione

This is usually unnecessary, because the global StdGen is seeded with the current time at startup. So you can just use randomIO and randomRIO and have an implicit, IO-based random number generator, or getStdGen and the usual pure functions for a more explicit one.

Altri suggerimenti

Are you looking for getPOSIXTime (docs)?

Footnote: Please note that this DOES NOT return the number of ticks since the beginning of any epoch, and you should never claim that it does. It returns the "POSIX time" which defined based on a lossy conversion from UTC time, and UTC time is not useful for determining intervals between dates without an up-to-date conversion database.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top