Need Help with Atompro28 code

Hello guys,

I was messing around with programming the AtomPro28 using the RANDOM Function. What I am trying to do is:

1.) Learn Mbasic
2.) Generate 10 random numbers, 0-9, for the purpose of a future project I have in mind.

I would like to be able to generate, randomly, 10 possible numbers and take the value to branch to a unique phrase to send to my SpeakJet. For example, when a particular event happens, say bump into a wall, that event would run a random generator routine before passing the value to the Bump in wall speech section. What this would do is let the software choose what to say for that particular event.

Possible Phrases:

  1. oops
  2. I need to watch were I am going!
  3. uh oh
  4. what’s this wall doing here?
  5. Yikes, did I do that?
  6. Darn programmers!
  7. I meant to do that.
  8. opps, didn’t mean to do that!
  9. If I only had a brain
  10. Where am I?

The problem I have right now is the random numbers are working except sometimes I get a really big number returned to me like 14734921 when it should be only one digit!

Here is the code example:

;-----------------------------------------------------------------------------------
; 
; Compiled using IDE version 08.0.0.0
; Program By Mike B.
; Debug ouput example using random generator
; MCU: AtomPro 28
;
;-----------------------------------------------------------------------------------

a var long

a = random TCA


loop

	a = random a ; uses "a" to generate a new "a"

	debug "Actual Number:   ", dec a, 13]			; Print the lable then value.
	debug "Modified Number: ", dec a dig 3, 13] 	; DIG 3: number returned 3 digits left from the right
													; Example: the number 100500 would return 5 because 5 is
													; the third digit counting from right to left <---------
	pause 5000	

	debug [0] ; clear the screen


goto loop

END

you could use the mod operand ( i.e. a = a // 10 ) to limit the range of responses to 0 through 9.

as to why you get an eratic value from a compiled program… probably just magic.

Hi, I have not used the RANDOM function yet on the Atom Pro, but looking at the manual it looks like it is supposed to return numbers in the range:
0 - 2(32nd power)

so the number you mentioned is fine. Another way to get a a single digit you could always do something like:

a = random a
debug "Single Digit: ", dec a//10, 13]

I am not sure what the dig 3 will do if your number is less than 100?

Kurt

Or you could just record 2^32 phrases. Ok, maybe not. :stuck_out_tongue:

I will have to try this and see what happens.

First let me say you won’t ever get truely random numbers out of a digital computer. But for close enough the rnadom command should be good enough. What is important is to start with as random a seed value as possible. The random function will return a number from 0 to 2^32-1. If you use the mod suggestion others made you can get a specific range. If you use the dig suggestion someone else made you can get a random number as well but if the number returned from Random is less than the digit you get you’ll get a 0 instead.