haskell / haskell/random

Add `instance Random DiffTime`

Open
#156 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
59
Forks
56
PR merge metrics
No merged PRs in 30d

Description

```haskell
instance Random DiffTime where
random :: (RandomGen g) => g -> (DiffTime, g)
random g =
let (i, g') = random g
in (picosecondsToDiffTime $ fromIntegral (i :: Integer), g')

randomR :: RandomGen g => (DiffTime, DiffTime) -> g -> (DiffTime, g)
randomR (a, b) g =
let (i, g') = randomR (diffTimeToPicoseconds a, diffTimeToPicoseconds b) g
in (picosecondsToDiffTime i, g')
```

Note that the instance can't go into `time` because of `random -> splitmix -> time` dependency chain.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.