Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,385
    • Issues 4,385
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 369
    • Merge Requests 369
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #5278

Closed
Open
Opened Jun 27, 2011 by rrnewton@trac-rrnewton

System.Random.randomIvalInteger makes invalid assumptions about RandomGen

The existing API for System.Random.RandomGen allows a random number generator (RNG) to produce Ints within an arbitrary range specified by genRange.

For example, the following RandomGen produces only zeros and ones, but should be legitimate:

import System.Random

data BinRNG = BinRNG StdGen
instance RandomGen BinRNG where 
  next (BinRNG g) = (x `mod` 2, BinRNG g')
    where (x,g') = next g
  split (BinRNG g) = (BinRNG g1, BinRNG g2)
    where (g1,g2) = split g
  genRange _ = (0,1)

ls :: [Int]
ls = randoms (BinRNG$ mkStdGen 38388)

main = print $ take 20 ls

But System.Random.randomIvalInteger makes invalid assumptions about the amount of randomness produced by next. (Specifically, assuming that it creates the same amount as StdGen.) Thus, the above program will create an output with only a couple of unique ints (rather than 2^64).

For example:

[4611734781337924537,4611734781337924537,-9223323645458902796,
-9223323645458902797,4611734783485408099,4611734783485408098,
-9223323645458902796,-9223323647606386357,4611734781337924538,
-9223323645458902796,-9223323645458902797,
-9223323647606386357,4611734783485408098,4611734783485408098,
-9223323647606386357,4611734781337924538,4611734781337924537,
-9223323645458902796,4611734783485408099,4611734781337924538]
Trac metadata
Trac field Value
Version 7.0.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/random
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#5278