# Putting the result of int(rnd( into a variable.

[b][red]This message was edited by Drakonik at 2005-7-18 17:7:9[/red][/b][hr]
How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.

• [b][red]This message was edited by IDK at 2005-7-20 11:2:15[/red][/b][hr]
: How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.
:
:
:
First, the left side of the statement
has to be a single variable, not the
right. Second, you'll have to end the
pharantase. Last, 1 * 5 = 5, you're
just making it more complicated.

This is how it should look like:
variable = int(rnd(5)) + 1

Edit:
Another thing I realised, is that this
way you'll get a number the number's
2,3,4,5,6. Is this what you wanted?
Don't you want the numbers 1,2,3,4,5?

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
• : [b][red]This message was edited by IDK at 2005-7-20 11:2:15[/red][/b][hr]
: : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.
: :
: :
: :
: First, the left side of the statement
: has to be a single variable, not the
: right. Second, you'll have to end the
: pharantase. Last, 1 * 5 = 5, you're
: just making it more complicated.
:
: This is how it should look like:
: variable = int(rnd(5)) + 1
:
: Edit:
: Another thing I realised, is that this
: way you'll get a number the number's
: 2,3,4,5,6. Is this what you wanted?
: Don't you want the numbers 1,2,3,4,5?
:
: [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
:

Well, I got the result into a variable. I had copied the code almost verbatim from the book I learned Liberty BASIC from. I think I'm fun with a tiny variation from what I expected. And, it's just for a game. An insignificant, no-longer-remember game, which I started trying to code months ago.
• : [b][red]This message was edited by IDK at 2005-7-20 11:2:15[/red][/b][hr]
: : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.
: :
: :
: :
: First, the left side of the statement
: has to be a single variable, not the
: right. Second, you'll have to end the
: pharantase. Last, 1 * 5 = 5, you're
: just making it more complicated.
:
: This is how it should look like:
: variable = int(rnd(5)) + 1
:
: Edit:
: Another thing I realised, is that this
: way you'll get a number the number's
: 2,3,4,5,6. Is this what you wanted?
: Don't you want the numbers 1,2,3,4,5?
:
: [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
:
I don't mean to cause any offense to Niklas Ulvinge, but since Rnd returns a random number from 0 to 1, and 0 * 5 = 0, then the +1 is nesecary for 1,2,3,4,5. but you are right, it would return 1,2,3,4,5,and 6, so you want to give it rnd(4)
the finished syntax: variable = int(rnd(4)) +1
• : : [b][red]This message was edited by IDK at 2005-7-20 11:2:15[/red][/b][hr]
: : : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.
: : :
: : :
: : :
: : First, the left side of the statement
: : has to be a single variable, not the
: : right. Second, you'll have to end the
: : pharantase. Last, 1 * 5 = 5, you're
: : just making it more complicated.
: :
: : This is how it should look like:
: : variable = int(rnd(5)) + 1
: :
: : Edit:
: : Another thing I realised, is that this
: : way you'll get a number the number's
: : 2,3,4,5,6. Is this what you wanted?
: : Don't you want the numbers 1,2,3,4,5?
: :
: : [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
: :
: I don't mean to cause any offense to Niklas Ulvinge, but since Rnd returns a random number from 0 to 1, and 0 * 5 = 0, then the +1 is nesecary for 1,2,3,4,5. but you are right, it would return 1,2,3,4,5,and 6, so you want to give it rnd(4)
: the finished syntax: variable = int(rnd(4)) +1
:
No, your right, it was a long time since I programmed in basic and I
often mix the funcs, the one I thought of was fix. But it wont return
6, becouse RND returns a number between 0 and 1, and the propability
that it will return 1 is almost 0.

Another thing, in qbasic the parameter to rnd is a number that will do
different things. If it's negative it will return the same number all
the time, and different things. Youre don't use qbasic so this wont
bother you.

In QBasic it would look like: INT(RND*5)+1
The thing's I've said is mostly for qbasic.
I don't know how your version acts.

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

• [b][red]This message was edited by moneo at 2005-8-20 16:30:41[/red][/b][hr]
: [b][red]This message was edited by Drakonik at 2005-7-18 17:7:9[/red][/b][hr]
: How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.
:
:
:
In order not to get mixed up regarding the range (from-to) of random numbers that the RND will produce, I suggest using the following standard function:

DECLARE FUNCTION RandInt% (lower, Upper)
RANDOMIZE TIMER

' ======================= RandInt% =============================
' Returns a random integer greater than or equal to the Lower parameter
' and less than or equal to the Upper parameter.
' ==============================================================

FUNCTION RandInt% (Lower, Upper) STATIC
RandInt% = INT(RND * (Upper - Lower + 1)) + Lower
END FUNCTION

*****