Help - Simple RANDOM program not giving me what I want.
SN96
Posts: 318
Hello
·
I have finished the "What's a microcontroller" Book and I want to start expanding on my PBASIC knowledge. I want to in the future,·be able to program my bot to have random behaviors. For example, I want to be able to have, as an example,·10 different behavior modes, and by using the RANDOM command, have those behaviors executed based on SELECTCASE values.
·
The problem I am having is: instead of retuning a random number from 0-9, I get values as high as 13 in the debug window? Am I not using the proper modifier? Please see my code bellow.
The code above is an experiment I used to try and understand how RANDOM works.
·
Thanks in advance, I appreciate any help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
"Don't always think outside the box, sometimes thinking inside the box is more pratical and simple."
·
I have finished the "What's a microcontroller" Book and I want to start expanding on my PBASIC knowledge. I want to in the future,·be able to program my bot to have random behaviors. For example, I want to be able to have, as an example,·10 different behavior modes, and by using the RANDOM command, have those behaviors executed based on SELECTCASE values.
·
The problem I am having is: instead of retuning a random number from 0-9, I get values as high as 13 in the debug window? Am I not using the proper modifier? Please see my code bellow.
' {$STAMP BS2} ' {$PBASIC 2.5} Result VAR Nib result = 9 'Set seed value of 9 DO RANDOM Result DEBUG DEC ? Result 'Print value to debug window PAUSE 200 LOOP
The code above is an experiment I used to try and understand how RANDOM works.
·
Thanks in advance, I appreciate any help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
"Don't always think outside the box, sometimes thinking inside the box is more pratical and simple."
Comments
DEBUG ? result//10
BRANCH result//10, [noparse][[/noparse]behavior0, behavior1,... ,behavior9]
That will display and branch on random numbers in the range of 0 to 9.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
"Don't always think outside the box, sometimes thinking inside the box is more pratical and simple."
·