Skip to content
A Haskell package providing a utility function for instantiating the System.Random.Random class.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/System/Random
.gitignore
.travis.yml
LICENSE
README.md
Setup.hs
random-derive.cabal

README.md

random-derive

Build Status

This module exposes a deriveRandom function which automatically creates Random instances for data types instantiating both Enum as well as Bounded.

This is useful for getting random values (or sequences of random values) of custom types, e.g.:

{-# LANGUAGE TemplateHaskell #-}

import System.Random (mkStdGen, randoms)
import System.Random.TH

data Color = Red | Green | Blue deriving (Enum, Bounded)

$(deriveRandom ''Color)

-- Yields an infinite sequence of random colors given some initial seed.
randomColors :: Int -> [Color]
randomColors seed = randoms (mkStdGen seed)
You can’t perform that action at this time.