Checking the PICAXE BASIC language manual shows a few possible problems with your code:
- the
timer
system variable has to be initialised with the settimer
command before you can use it
- depending on what preload value you use with
settimer
, the value of timer
may well not have changed in the short time between one loop iteration and the next, which will give you the same result from random
random
should be used with a word variable (w0, w1, etc) not a byte variable
What I think the manual entry for random
is suggesting you should do, although I agree it isn't exactly clear if you're new to random number generation, is to seed random
with timer
the first time you call it, then seed it with its own previous value each time after that:
symbol counter = b5
let w3 = timer ; w3 is the word variable consisting of b6 and b7
for counter = 0 to 10
random w3
; ...do something with the value of w3 (but don't change w3 itself)...
next counter
However after saying all this, it is certainly possible that the simulator in one or other version of the PICAXE Programming Editor doesn't simulate the behaviour of timer
correctly in all cases. If you can't get the code working on a real PICAXE, take this question to the PICAXE forum where it will be seen by Revolution Education support staff as well as other knowledgeable users.