CompuServe Thread

#Manx help

8 messages in this thread
#364From: Henry WilliamsSep 13, 1990 10:13 AM
Hello Mike, I have another question for you about using this wonderful (and confusing to me), Manx 3.6a compiler. I want to use the random generator but don't seem to be able to get it to work. I see the Synopsis shows: double ran() .It also says that the value returned will be a number between 0.0 and 1.0 . How do I get a variable to equal the returned number? Can I put an argument (somehow) between the brackets? And how do I get the function to give me a random number between 1 to 50 for example? My gosh I have another question <smiling>. I noticed quite a few examples in the vt100 directory. If it's not too much trouble, could you tell me which ones are actually needed to make a very simple communication program, as well as any other files I will need? Thank you for any help you can give me. Henry PS: Fortunately, I don't have to feed myself by programming computers.
#369From: Peter SmithemSep 13, 1990 11:53 AM
Henry, double RandomNumber; int OneTwoFifty; RandomNumber = rand(); OneTwoFifty = (INT) (RandomNumber * 50.0 + 0.5); Should work, assuming that I'm awake today <grin>. Peter_S (LeCroy Corp) "Software is never having to say you're finished"
#374From: Henry WilliamsSep 13, 1990 3:07 PM
Hi Peter, Thanks for the help. I'll try this and see if you were awake 🙂 Regards, Henry
#377From: Mike Spille/ManxSep 13, 1990 3:38 PM
You need to use the mod function (%) not multiply (*) to get the range right. -Mike
#412From: Peter SmithemSep 14, 1990 12:37 PM
Oops, I typo'ed the function name. He said ran(), double function returning a number between 0 and 1, not rand() which returns an integer (range depends on your implementation). Peter_S (LeCroy Corp) "Software is never having to say you're finished"
#376From: Mike Spille/ManxSep 13, 1990 3:37 PM
ran() should only be used if you need a floating point random number. If you're interested in integer stuff (which is the usual case), you say something like: foo () { int val; val = rand(); } rand() is similar to ran(), except that it returns an integer between 0 and 32767. If you need a range between say 1 and 50, you'd say something along the lines of: val = (rand() % 50) + 1; -Mike
#411From: Matthew J. W. RatcliffSep 14, 1990 11:57 AM
Great idea… i have been wasting time using a #define Rndm(x) (x * rand())/MAX_RAND … I like mod better already
#461From: Henry WilliamsSep 15, 1990 5:50 PM
Hi Mike, Thanks thats just what I needed. I tried the other example and it didn't quite make it. Henry