<DIV>Thanks Stefan,</DIV>
<DIV> </DIV>
<DIV>Sorry for sending the message to the bug list. My first post to</DIV>
<DIV>the users mailing list seems to get lost somewhere. I therefore try </DIV>
<DIV>my luck on the bug list. It seems to work :)</DIV>
<DIV> </DIV>
<DIV>I am extending my polyGP system using the new haskell compiler.</DIV>
<DIV>The random number is to be used for selecting crossover/mutation </DIV>
<DIV>points, not to be printed (not IO type). I tried the following and they</DIV>
<DIV>seem to work fine. </DIV>
<DIV> </DIV>
<DIV>-- get a list of random int between 1 and 250</DIV>
<DIV>drawInt :: [Int]<BR>drawInt = randomRs (1, 250)(mkStdGen 10)<BR></DIV>
<DIV>-- get a list of random double between 0 and 100 <BR>drawDouble :: [Double]<BR>drawDouble = randomRs (0, 100) (mkStdGen 100)<BR></DIV>
<DIV>Are they really random numbers ? I am wodering why all</DIV>
<DIV>random double has values < 1.0. Do you know ? Thanks !!</DIV>
<DIV> </DIV>
<DIV>Tina<BR><B><I>Stefan Reich <doc@drjava.de></I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">That's definitely not a message for the bugs list :-)<BR><BR>Please have a look at this page: <BR>http://www.zvon.org/other/haskell/Outputrandom/getStdRandom_f.html<BR><BR>It gives the correct signature for drawInt as you defined it: Int -> Int <BR>-> IO Int<BR><BR>The signature you gave doesn't work because it specifies a pure function <BR>- for the same set of arguments, it must always produce the same result.<BR><BR>How many ints do you want to generate? I don't think it is possible to <BR>generate an infinite lazy list in this case because this interferes with <BR>monad semantics. If you want a fixed number of random ints, try this:<BR><BR>drawInts :: Int -> Int -> Int -> IO [Int]<BR>drawInts num x y = sequence (replicate num (getStdRandom (randomR (x,y))))<BR><BR>-Stefan<BR><BR>Gwoing Yu wrote:<BR><BR>> Hi,<BR>> <BR>> I need some assistances in calling
random number generator using 6.0.1 <BR>> haskell compiler. To return a list of random int [Int], I have tried <BR>> the following:<BR>> <BR>> drawInt :: Int->Int -> [Int]<BR>> drawInt x y = getStdRandom (randomRs (x,y))<BR>> <BR>> It has a type error. I would appreciate if you know how to fix it.<BR>> <BR>> Thank you in advance.<BR>> <BR>> Tina Yu<BR>> http://www.improvise.ws <HTTP: www.improvise.ws /><BR></BLOCKQUOTE><p><hr SIZE=1>
Do you Yahoo!?<br>
Yahoo! Hotjobs: <a href="http://pa.yahoo.com/*http://us.rd.yahoo.com/hotjobs/mail_footer_email/evt=21482/*http://hotjobs.sweepstakes.yahoo.com/signingbonus">Enter the "Signing Bonus" Sweepstakes</a>