Just how random is PICAXE random?

Jamster

Senior Member
I decided to venture in to the randomness of the random command after seeing this sparkfun tutorial, the graph made me wonder about the PICAXE command and whether it's as uneven and 'spikey' as that.

The PICAXE used was an 08M2 and the code as follows:

Code:
main: random w0
 sertxd (b0)
 pause 10
 goto main
The results (attached) are relatively even with no obvious spikes within the 10 minutes I ran the program for.

If anyone wants me to run tests (eg on scale down methods) I'm back at my PICAXE on tuesday and will be running a longer test. :)

Jamster
 

Attachments

srnet

Senior Member
One of the issues with testing for randomness is basic ...... you cant.

'Spikes' in the output could be normal, so what you are really testing is whether the function returns a 'even' spread of numbers, which may or may not be random.
 

hippy

Ex-Staff (retired)
Random on the PICAXE is implemented as a Linear Feedback Shift Register; a shift register with taps which form a new lsb for the variable, so the random number sequence is entirely predictable along the lines of ...

var = ( var * 2 ) + ( var.bitX ^ var.bitY ^ var.bitZ )

For every 65536 generations, every one of the 0 to 65535 numbers will be generated and only once, and every 65536 generations will be the same as each other. So by some definitions of 'random', not random at all.
 

IronJungle

Senior Member
Not 100% true. If the graph was re-plotted several times and the "spikes" occurred repeatable intervals that would point to a randomness problem; possibly a repeatable seed number.


One of the issues with testing for randomness is basic ...... you cant.

'Spikes' in the output could be normal, so what you are really testing is whether the function returns a 'even' spread of numbers, which may or may not be random.
 

srnet

Senior Member
Not 100% true. If the graph was re-plotted several times and the "spikes" occurred repeatable intervals that would point to a randomness problem; possibly a repeatable seed number.
That could point to a problem with the generation of random numbers, but then such skewed behaviour could also be random behaviour, however unlikley that may seem.
 

mrburnette

Senior Member
... but, the question to be asked is, "Is it random 'nuff?" And this gets to the heart of the problem... pseudo-random generation: PRBS. The very fact that we are taking about random numbers AND the PICAXE in the same sentence suggests (to me) that as long as Hippy's explanation is factual (and who would doubt Hippy? Not I.) that it is adequate.

What I would find terribly interesting is knowing the effects of single-seeding verses multiple seeding of the generator.
In a recent thread for help, an array needed to be annotated for random player selection. Project-for-creating-and-displaying-a-table (Post #5)and I elected to pair the seeding and randomizing for each loop iteration. Without going through an entire mathematical thesis, would a single seeding have been sufficient/preferable?


- Ray
 
Last edited:

srnet

Senior Member
... but, the question to be asked is, "Is it random 'nuff?"
And the answer that most people want is an even spread of numbers over a large number of iterations, which is fine.

In other words what people expect to see is predicatability of results, not randomness.
 
Top