I am learning Just BASIC and I want to know the following.
If (how is the code written, what does it do.)
then (how is the code written, what does it do.)
How can I make a variable equal a random number?
Offline
IF x=y THEN (carry out an operation)
Where x and y are either constants, program variables or strings, and "Carry out an operation" is a line of code exactly as you might put on its own.
For example
IF Score=10 THEN PRINT "You win!"
IF answer="No" THEN GOTO 200
Offline
Mayhem wrote:
IF x=y THEN (carry out an operation)
Where x and y are either constants, program variables or strings, and "Carry out an operation" is a line of code exactly as you might put on its own.
For example
IF Score=10 THEN PRINT "You win!"
IF answer="No" THEN GOTO 200
Thanks for the help, and do you know the answer to the randomizing?
Offline
I've never used BASIC. I know how to do it in flash - though.
Offline
urhungry wrote:
Did you try set variable to random 1-10?
He needs to know how to do it in BASIC, not Scratch.
Just Googled the answer, try [variable] = Rand(min, max)
Offline
It depends on teh version of Basic.
In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.
So to get a random number from 1-6, for example, there are 4 steps
1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6
Fortunately, all of that can be done as one line. If I remember correctly it would something like:
INT (RND*6)+1
Offline
technoguyx wrote:
urhungry wrote:
Did you try set variable to random 1-10?
He needs to know how to do it in BASIC, not Scratch.
Just Googled the answer, try [variable] = Rand(min, max)
yes, I know, I wasn't exactly sure, but I knew it was something like that.
Offline
Mayhem wrote:
It depends on teh version of Basic.
In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.
So to get a random number from 1-6, for example, there are 4 steps
1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6
Fortunately, all of that can be done as one line. If I remember correctly it would something like:
INT (RND*6)+1
I believe I mentioned it's Just BASIC.
Anyway, that always returns as one.
Last edited by soupoftomato (2010-02-16 15:53:31)
Offline
BBC BASIC? Commodore BASIC? Sinclair BASIC? - all are "Just BASIC" but all are subtly different.
Offline
Go to justbasic.com whatever program you download there. But my dad figured it out.
Offline
soupoftomato wrote:
Mayhem wrote:
It depends on teh version of Basic.
In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.
So to get a random number from 1-6, for example, there are 4 steps
1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6
Fortunately, all of that can be done as one line. If I remember correctly it would something like:
INT (RND*6)+1I believe I mentioned it's Just BASIC.
Anyway, that always returns as one.
It sounds like it is treating RND as a variable with value of zero. Try using RND(0) so that it knows you are looking for a function result. You can also check the documentation here
http://justbasic.conforums.com/index.cgi?board=tutorial&action=display&num=1188307611
Offline
Paddle2See wrote:
soupoftomato wrote:
Mayhem wrote:
It depends on teh version of Basic.
In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.
So to get a random number from 1-6, for example, there are 4 steps
1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6
Fortunately, all of that can be done as one line. If I remember correctly it would something like:
INT (RND*6)+1I believe I mentioned it's Just BASIC.
Anyway, that always returns as one.
It sounds like it is treating RND as a variable with value of zero. Try using RND(0) so that it knows you are looking for a function result. You can also check the documentation here
http://justbasic.conforums.com/index.cgi?board=tutorial&action=display&num=1188307611
Thanks for the help, but after further "research" I have figured it out, for 1-10 use RND((1)*10)10, or somehting like that, but it's included in the help so . . .
Offline