Random Number Generation

benbaker7

Active member
Hi Folks. In tinkering with the RANDOM function, I have found that the results I've produced with the simulator seem to be at variance with the detail on p.177 of the Manual.

I used the following listing :

main: ;08M2, Editor 5.5.5, XP platform ( I'm more comfortable with PE5 than 6)
random w0
w1=w1+1 ; cycle counter
if b0 <= 50 then high c.0 stop endif
goto main

This program produces a different sequence of numbers each time it is simulated, where the Manual, for quite logical reasons, states that the same sequence should be generated on each cycle. The program stops and c.0 lights when the random number generated is =< 50, executes a different number of cycles between each iteration, and produces a different value each time. . It seems unnecessary therefore, to change the seed as in the examples listed.

On the basis that the Manual is right and I am wrong, I would be interested in the comments of someone more experienced than I, in unravelling this mystery.

Thanks
Ben Baker
 

Flenser

Senior Member
This program produces a different sequence of numbers each time it is simulated
What is the program you are running to report these numbers and can you give us an example of the different sequence of random numbers it produces?

I've just run the following code in PE v6.1 simulation twice as 08m:
Code:
main:
random w0
sertxd(#b1, ":", #b0, cr, lf)
w1=w1+1 ; cycle counter
if w1>50 then stop endif
goto main
and I got exactly the same set of random numbers each time:
Code:
First run
0:2
0:5
0:11
0:23
0:47
0:94
0:189
1:122
2:244
5:232
11:208
23:161
47:66
94:133
189:11
122:22
244:45
232:90
208:181
161:107
66:214
133:173
11:90
22:180
45:104
90:208
181:161
107:67
214:135
173:15
90:31
180:63
104:126
208:253
161:251
67:247
135:239
15:223
31:191
63:127
126:255
253:255
251:254
247:252
239:249
223:242
191:229
127:202
255:149
255:43
254:86

Second run
0:2
0:5
0:11
0:23
0:47
0:94
0:189
1:122
2:244
5:232
11:208
23:161
47:66
94:133
189:11
122:22
244:45
232:90
208:181
161:107
66:214
133:173
11:90
22:180
45:104
90:208
181:161
107:67
214:135
173:15
90:31
180:63
104:126
208:253
161:251
67:247
135:239
15:223
31:191
63:127
126:255
253:255
251:254
247:252
239:249
223:242
191:229
127:202
255:149
255:43
254:86
 

benbaker7

Active member
Hi Flenser. I'm not doing anything clever with the code - just testing it out. I ran it 3 times and got - 137,15 (stopped), 111,43 (stopped) and 185,197,30 (stopped). I also modified the code using sertxd and got similar results on the output screen(of course). Also checked an earlier version of the manual, but the text is essentially the same, so it doesn't look like a variation between PE 5 and 6. So I can't figure why you are getting the expected similarity, yet I'm getting different results each time.

Ben Baker
 

benbaker7

Active member
Hello again Flenser. Used PE6 and modified the action line to >50 and got exactly the same results as you. I don't like PE6, but it seems that I'll have to us it from here on in (I also prefer carburetted engines rather than fuel injected).
Alley Cat sent me a snippet which explains a lot and which you may find interesting also. Thanks AC

Ben Baker
 

hippy

Ex-Staff (retired)
This program produces a different sequence of numbers each time it is simulated, where the Manual, for quite logical reasons, states that the same sequence should be generated on each cycle.
When I run this under PE6 simulation I get the same sequence every time, same as Flesner's result, which accurately reflects the pseudo random number nature of the RANDOM command -
Code:
For w1 = 1 To 14
  Random w0
  SerTxd( #w0, " " )
Next
Code:
2 5 11 23 47 94 189 378 756 1512 3024 6049 12098 24197
main: ;08M2, Editor 5.5.5, XP platform ( I'm more comfortable with PE5 than 6)
If using PE5 I recall that did behave differently, generated an actual random number every time which does not match the behaviour of the actual PICAXE chip.
 
Top