
Hi, is the are way (or a build in method) in haskell to get a random number from a number bottom to a number top? Something like let randomNumber = random 1 30 to get a random number between 1 and 30. -- View this message in context: http://www.nabble.com/Random-Number-tp23914474p23914474.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

look in System.Random
randomRIO :: (Random a) => (a, a) -> IO a
you can do
randomNumber<-randomRIO (1,30)
On Sun, Jun 7, 2009 at 3:33 PM, ptrash
Hi,
is the are way (or a build in method) in haskell to get a random number from a number bottom to a number top?
Something like
let randomNumber = random 1 30
to get a random number between 1 and 30. -- View this message in context: http://www.nabble.com/Random-Number-tp23914474p23914474.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Jun 7, 2009 at 21:33, ptrash
Hi,
is the are way (or a build in method) in haskell to get a random number from a number bottom to a number top?
Something like
let randomNumber = random 1 30
to get a random number between 1 and 30.
I don't mean to be rude, but did you even tried to read the documentation? The function you want is here: http://www.haskell.org/ghc/docs/latest/html/libraries/random/System-Random.h... Before you ask any other questions please read this essay: http://mattgemmell.com/2008/12/08/what-have-you-tried Best regards Krzysztof Skrzętnicki

On 7 Jun 2009, at 8:33 pm, ptrash wrote:
Hi,
is the are way (or a build in method) in haskell to get a random number from a number bottom to a number top?
Something like
let randomNumber = random 1 30
to get a random number between 1 and 30.
rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) this worked for me, I also had quite a few random questions on here a few months ago! :) Beware it is an IO int. On 7 Jun 2009, at 8:55 pm, Krzysztof Skrzętnicki wrote:
I don't mean to be rude, but did you even tried to read the documentation? The function you want is here: http://www.haskell.org/ghc/docs/latest/html/libraries/random/System- Random.html
Before you ask any other questions please read this essay: http://mattgemmell.com/2008/12/08/what-have-you-tried
Best regards
Krzysztof Skrzętnicki
Bit harsh isn't it? He asked for an example function, not an entire program. Iain
participants (4)
-
Iain Barnett
-
José Prous
-
Krzysztof Skrzętnicki
-
ptrash