Differences between programmer 5 and programmer 6

john thorne

New Member
I want to generate 3 different random numbers in W0 W1 and W2 running in a loop until a button is pressed.
This works fine in version 5, I get 3 different numbers in W0 W1 and W3 on each loop.
In version 6 I get the same random number in W0 W1 and W3 on each loop.
Any Ideas
 

john thorne

New Member
Hi
Thanks for the reply. I just used this to test both versins

Code:
start:
random W0
pause 500
random W1
pause 500
random W2
pause 500
random W3
pause 500
if pinc.1 =1 then
goto test
endif
goto start


Test:
W4=W0 //100 + 1
pause 1000
goto start
 
Last edited:

Technical

Technical Support
Staff member
We assume you are simulating, in which case PE6 simulates much more like a real chip actually would, PE5 did not simulate random very well.

Make sure you are using a seed (currently 0 in your example) or repeatedly calling random within a fast loop to get a 'random' result - currently you are not.
 

hippy

Ex-Staff (retired)
This is presumably while simulating. PE6 reflects what an actual PICAXE chip would do, while PE5 does not.

It is possible to randomly seed a random number when a program starts in simulation under PE6 by using the 'ppp_time' and other pre-processor substitutions to set the initial random number start condition ...

Code:
Symbol randomNumber     = w0 ; b1:b0
Symbol randomNumber.lsb = b0
Symbol randomNumber.msb = b1

[b]LookUp 6, ( ppp_time ), randomNumber.lsb
LookUp 7, ( ppp_time ), randomNumber.msb[/b]

For b7 = 1 To 10
  Random randomNumber
  SerTxd(#randomNumber," ")
Next
 

john thorne

New Member
Thanks again for the reply and clarifying that PE 5 does not reflect the chip I assumed it did.
I'm not sure what you mean by " 'ppp_time' and other pre-processor substitutions " I can't find any reference to it in the manuals.
Will this work for 3 random numbers in W0 W1 and W3.
 

hippy

Ex-Staff (retired)
I'm not sure what you mean by " 'ppp_time' and other pre-processor substitutions " I can't find any reference to it in the manuals.
http://www.picaxe.com/BASIC-Commands/Directives/preprocessor

Will this work for 3 random numbers in W0 W1 and W3.
Yes, providing they are all seeded differently, have different start values. One way to do that might be to add an offset to each before using them ..

LookUp 6, ( ppp_time ), b0
LookUp 7, ( ppp_time ), b1
w1 = w0 + 17 : Random w1
w2 = w1 + 19 : Random w2

I was calling random in a fast loop and I'm still not sure why W0 W1 W2 W3 all give the same number
Probably because all variables started at the same value so each will step to the next same 'random number' in synchronisation.

RANDOM doesn't 'pluck a random number from the air' but creates the next number from what the variable currently contains.
 
Top