random numbers in pbasic?
Im still new to basic so let me discribe my issue.
I have a boebot that is roaming with a sonic sensor. I wrote all this code myself and its working quite well. when this program is done I will post it here for others to look at and give feedback on.
right now, my bot goes forward with the sonic sensor pinging away. every so often, the bot stops and the the sonic sensor pings in 3 different directions and saves the values. depending on what those values are the bot turns and gos on its way..
so there is a value in 3 drections but if there is an object in the forward direction and nothing to the sides.. ie· 0 1 0 .. I have the bot truning to the 15 degrees·right and starting forward on its way again. what i would like to happen is.. the the case of 0 1 0.. I would like a random 50/50 chance to trun right or left.. and contunue on its way..
problem is I have no idea how to do this in pbasic. I understand how and where I need to branch and return to.. but as far as the random 50/50 chance im clueless. I am assuming that I need some kind of counter or something but how to stop it randomly is the real quesion? after that its simple evaluation to get to the result..
anyway.. does anyone have any ideas or pointers?
thanks for your time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
Post Edited (Muahdib) : 12/6/2006 4:20:42 PM GMT
I have a boebot that is roaming with a sonic sensor. I wrote all this code myself and its working quite well. when this program is done I will post it here for others to look at and give feedback on.
right now, my bot goes forward with the sonic sensor pinging away. every so often, the bot stops and the the sonic sensor pings in 3 different directions and saves the values. depending on what those values are the bot turns and gos on its way..
so there is a value in 3 drections but if there is an object in the forward direction and nothing to the sides.. ie· 0 1 0 .. I have the bot truning to the 15 degrees·right and starting forward on its way again. what i would like to happen is.. the the case of 0 1 0.. I would like a random 50/50 chance to trun right or left.. and contunue on its way..
problem is I have no idea how to do this in pbasic. I understand how and where I need to branch and return to.. but as far as the random 50/50 chance im clueless. I am assuming that I need some kind of counter or something but how to stop it randomly is the real quesion? after that its simple evaluation to get to the result..
anyway.. does anyone have any ideas or pointers?
thanks for your time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
Post Edited (Muahdib) : 12/6/2006 4:20:42 PM GMT
Comments
-Phil
so tell me if there is anything wrong with this bit of code
Randomnum:
IF counter2 > 14 THEN
counter = 0
counter2 = rvalue
ENDIF
RANDOM rvalue
counter2 = counter2 + 1
IF rvalue > 32767 THEN
GOSUB TurnR
ELSE
GOSUB TurnL
ENDIF
RETURN
I have made 2 varibles one is a nib and one is a word. Im using the nib to count from 0 to 14 . making that value the seed value
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
thanks.. for the input..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
So grabbing BIT0 is the same as saying Value//2. BIT0 will be 0 if the number is even and 1 if the number is odd, in other words. Now, for your particular random scenario, you could actually grab *any* bit.
You could also do something similar with a lookup table, or an ON statement, whatever:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Post Edited (Zoot) : 12/7/2006 1:55:18 PM GMT
Random generator = (time in seconds/encoder wheel count)*2
if random generator is even then turn left
if random generator is odd the turn right
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona