Skip to content

Commit

Permalink
Add intial implementation of SeedGen
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Feb 3, 2024
1 parent 8ed7788 commit f23a173
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 1.3.0

* Add `Seed`, `SeedGen`, `seedSize`, `mkSeed` and `unSeed`:
[#162](https://github.com/haskell/random/pull/162)
* Add `SplitGen` and `splitGen`: [#160](https://github.com/haskell/random/pull/160)
* Add `shuffleList` and `shuffleListM`: [#140](https://github.com/haskell/random/pull/140)
* Add `mkStdGen64`: [#155](https://github.com/haskell/random/pull/155)
Expand Down
16 changes: 13 additions & 3 deletions bench-legacy/SimpleRNGBench.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{-# LANGUAGE BangPatterns, ScopedTypeVariables, ForeignFunctionInterface #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fwarn-unused-imports #-}

-- | A simple script to do some very basic timing of the RNGs.

module Main where

import System.Exit (exitSuccess, exitFailure)
Expand Down Expand Up @@ -80,13 +85,18 @@ measureFreq = do

-- Test overheads without actually generating any random numbers:
data NoopRNG = NoopRNG
instance SeedGen NoopRNG where
type SeedSize NoopRNG = 1
seedGen = error "NoopRNG"
unseedGen = error "NoopRNG"
instance RandomGen NoopRNG where
next g = (0, g)
genRange _ = (0, 0)
split g = (g, g)

-- An RNG generating only 0 or 1:
data BinRNG = BinRNG StdGen
newtype BinRNG = BinRNG StdGen
deriving (SeedGen)
instance RandomGen BinRNG where
next (BinRNG g) = (x `mod` 2, BinRNG g')
where
Expand Down
5 changes: 5 additions & 0 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module System.Random
, genWord64R
, unsafeUniformFillMutableByteArray
)
, SeedGen (..)
, Seed
, mkSeed
, unSeed
, seedSize
, SplitGen (splitGen)
, uniform
, uniformR
Expand Down
Loading

0 comments on commit f23a173

Please sign in to comment.