Computer Science Canada [Sample] Basic Random Numbers |
Author: | cool dude [ Wed Oct 06, 2004 7:05 pm ] | ||
Post subject: | [Sample] Basic Random Numbers | ||
scroll down hi, i don't know if there is already a tutorial like this but i'm going to post it anyways to help teach the nubes. lol whenever you want to use random numbers in turing you have to use the word randint and put the numbers you want turing to randomly pick out from. below is an example of what i mean. i put some comments in for you to understand exactly why i put some things. i hope you learn from this. enjoy!
|
Author: | Tony [ Wed Oct 06, 2004 8:20 pm ] | ||
Post subject: | |||
randint is a preaty bad way to do it You're better off with Rand.Int(low, high)
|
Author: | Delos [ Wed Oct 06, 2004 8:27 pm ] | ||||||||
Post subject: | |||||||||
Hmm... Well, I guess since it was for "extreme newbies"... First off, in the future please check your code before you post it. This code was buggy...your for loop does not work correctly. Random Numbers, eh? Random numbers in Turing, as in (just about, if not) all programming languages are not really random. They're just generated from a list so they seem random. As mentioned, one has the randint() routine. This randomizes an integer. Thusly:
Here 'number' is assigned a value from 1 to 10. One could also say:
and the same would be true. So we have integers, what about real numbers? We use rand():
Note that one does not specify a domain for the function, the variable is automatically assigned a value from 0 - 1 (to six decimal places). One could also use:
with the same effect. There are a number of other Rand.() functions available, but these deal with situations in which strings of random numbers are required, but the same sequence needs to be generated each time. So, for 'extreme newbies', there is no need to worry. If in doubt, press F10! Muwahahahaahaha. ARGH! Beaten to the post by tony...meh |
Author: | cool dude [ Fri Oct 08, 2004 1:19 pm ] |
Post subject: | |
sorry, my bad. didn't realize i wrote the code wrong. |
Author: | Tony [ Fri Oct 08, 2004 6:34 pm ] |
Post subject: | |
that's ok - you tried |