Computer Science Canada Random Integer help! |
Author: | bvbjules13 [ Wed Oct 31, 2012 3:25 pm ] |
Post subject: | Random Integer help! |
What is it you are trying to achieve? i am trying to have 25 variables each have a random number between 1-100 What is the problem you are having? if i use one variable with the value Rand.Int (1,100), each time time i use the variable will the random number be the same or will it be different each time it is called/used Please specify what version of Turing you are using 4.1 |
Author: | Zren [ Wed Oct 31, 2012 3:59 pm ] | ||||||
Post subject: | RE:Random Integer help! | ||||||
If you assign a value to a variable, does it change each time your read/access it? Rand.Int (1,100) is a function call that will generate and return a pseudo-random number.
Turing interprets the above as: It will call Rand.Int(1, 100). Eg: say it returns 34.
Then it will define the variable num as the int datatype as Turing assumes your variable's data type must be an integer as that is the type you're trying to use with it.
You are assigning a number value to the variable num. You are NOT assigning the function to another name. You will be returning the value you assigned to it when you call it. You will not be calling Rand.Int(1, 100) as if it were a shortcut if you call the variable. The latter is possible however (in other languages if not Turing), but that's for another lesson. |
Author: | mirhagk [ Wed Oct 31, 2012 4:13 pm ] |
Post subject: | RE:Random Integer help! |
If you are using 25 variables it may be time to look into arrays. Be careful not to take on too ambitious projects before you learn the required concepts. |
Author: | chipanpriest [ Wed Oct 31, 2012 5:44 pm ] | ||||||
Post subject: | Re: Random Integer help! | ||||||
If you have a variable with a value of Rand.Int (1,100), that variable will choose a number, and stay that number. For example:
To have 25 different variables you could either make 25 different variables:
Or, you could make an array, which is easier to keep track of and will make your program less cluttered and have less lines of code:
If you don't understand this array stuff, I'm sure there's a tutorial on arrays. |
Author: | bvbjules13 [ Wed Oct 31, 2012 9:34 pm ] |
Post subject: | Re: Random Integer help! |
Thanks you guys! definiftly helped, i just ended up creating 25 variables with random integers ^.^ my course wont let me do it another way |