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.
Type Name Latest commit message Commit time
Failed to load latest commit information.


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.