Course talk:CPSC312-2016-not-my-number

From UBC Wiki

Contents

Thread titleRepliesLast modified
Comments119:06, 1 December 2016

Sorry for the late reply. I just had time to think about your question that you asked during today's office hour.

You may assign the generated random number to a variable in a do block. Then you may use that variable as many times as you want in that do block.

See below. The body of the do block is boxed. Note that y is always equal to x + 1 + x * x.


-- Code starts here.

module Test where

import System.Random

foo x = x + 1

bar x = x * x

testCode = do

 x <- randomRIO (0,100::Int) 
 -- Now you may use x as a randomly generated number. 
 print x
 y <- return (foo x + bar x)
 print y
Rge (talk)23:14, 28 November 2016

Hey Rui,

Thanks for replying!

I actually decided to work around the problem .... by doing something completely, mildly, different.

You can check the GitHub if you are interested, otherwise... I won't be sad if you don't.

HyojinYi (talk)19:06, 1 December 2016