[Haskell] How to get different two random numbers

Stefan Holdermans sholderm at students.cs.uu.nl
Wed Oct 6 03:23:47 EDT 2004


ldou,

  LD> How to get different two random numbers, and use the two
  LD> numbers in program,e.g
  LD> x = b + c
  LD> where
  LD> b && c are different random numbers between 1..n

Have a look at the Random module from the standard libraries.

> module Test where
> import Random
>
> test   :: Integer -> IO Integer
> test n =  do b <- randomRIO (1, n)
>              c <- randomRIO (1, n)
>              let x = b + c
>              return x

HTH,

Stefan



More information about the Haskell mailing list