Random
![[Deleted User]](https://images.v-cdn.net/banned_large.png)
Hi , I was wondering if anybody knew if you could put a limit on "RANDOM"· , say you only want numers from 0 to 13 . Is it possible to make it so RANDOM could only choose between those number's
thanks,
brian
thanks,
brian
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
r var byte
random r//14
also can you use more than one random in a row, like
random color
random character
random ypos
random xpos
Well, look at the syntax for the RANDOM command in the PBASIC Help file.
So.... you really do something more like this
The first line gets a random number and the second line reduces that
random number to 0 to 13. You don't necessarily have to reassign it
back to 'r' -- you can use "r // 14" as part of an expression. BUT, if
you need that value again the MODULO operator will have to be calculated again.
{EDIT: Oooppsss! After using the modulo operator on the output of RANDOM
you REALLY don't want to reassign it back to 'r' (in this case) because the value
of 'r' will be used to seed the random number generator next time you call execute
RANDOM r. This will then cause your code to use the same 14 numbers from RANDOM
over and over again. Probably not what you want.}
Yup!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Rusty-
--
Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
**Out yonder in the Van Alstyne (TX) Metropolitan Area**
Microsoft is to software what McDonalds is to gourmet cooking
Post Edited (Fe2o3Fish) : 10/22/2006 5:01:59 AM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
'screen saver program
color VAR Byte
xpos VAR Byte
ypos VAR Byte
'clear screen
SEROUT 15,84,1,[noparse][[/noparse]83,0]
PAUSE 1600
main:
· RANDOM color
· color = color//14
· RANDOM xpos
· xpos = xpos//188
· RANDOM ypos
· ypos=ypos//255
'random color,postion sqaure
SEROUT 15,84,1,[noparse][[/noparse]67,31,COLOR,XPOS,YPOS]
PAUSE 17
GOTO main
thank's Brian
Post Edited (truckwiz) : 10/22/2006 1:54:17 PM GMT
color VAR Byte
xpos VAR Byte
ypos VAR Byte
rnd VAR Word
'clear screen
SEROUT 15,84,1,[noparse][[/noparse]83,0]
PAUSE 1600
main:
· RANDOM rnd
· color = rnd//14
· RANDOM rnd
· xpos = rnd//188
· RANDOM rnd
· ypos = rnd//255
'random color,postion sqaure
SEROUT 15,84,1,[noparse][[/noparse]67,31,COLOR,XPOS,YPOS]
PAUSE 17
GOTO main
it would still work if you left out the last two RANDOM statements but I think the way it is has the edge in my opinion.
Jeff T.
Thanks ,Brian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Thank's
Brian