ZVON > References > Haskell reference
| Indexes | Syntax | Prelude | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | >> Random <<

Module: Random
Function: randomR
Type: (Random a, RandomGen b) => (a,a) -> b -> (a,b)
Class: Random
Description: randomR takes a range (lo,hi) and a random number generator g, and returns a random value uniformly distributed in the closed interval [lo,hi], together with a new generator.
Related:

Example 1
Program source: 

import Random

main = do a <- drawInt 1 10
 	  b <- drawInt 1 10
 	  x <- drawDouble 0.0 1.0
 	  print a
	  print b
	  print x

drawInt :: Int -> Int -> IO Int
drawInt x y = getStdRandom (randomR (x,y))
	   
drawDouble :: Double -> Double  -> IO Double
drawDouble x y = getStdRandom (randomR (x,y))

Output: 6

Output: 2

Output: 0.8674070605466624