-
Random number results
After that week of trying to understand how random would work here are some results from my test:
Random number output from chip 12F629:
2 - 5- 11- 7- 15 - 14 - 13 - 10 -4 - 8- 0 - 1 - 2 - 5
11 - 6 - 13 - 10 - 5 - 11 - 6 - 13 - 10 - 4 - 8 - 0 - 1 - 3
7 - 15 - 15 - 15 - 14 - 13 - 11 - 7 - 15 - 15 - 15 - 15 - 15 - 15
14 - 12 - 9 - 2 - 5 - 10 - 5 - 11 - 6 - 12 - 8 - 0 - 0 - 1 - 3 - 6
There does seem to be some strange duplications of numbers in the above string that was generated.
0 - 4
1 - 3
2 - 2
3 - 2
4 - 1
5 - 4
6 - 4
7 - 3
8 - 3
9 - 1
10 - 4
11 - 5
12 - 2
13 - 4
14 - 3
15 - 10
Generally there is an even distribution of numbers in the above list except for number 15 which was generated at least twice as many times as any other number.
0 - 7 count is 23
8 - 15 count is 29
These numbers were generated using:
start:
<b>Random rannum
If rannum = 66535 then start ' get an even distribution of odd and even numbers
number = rannum & $000F</b>
I think the same results would come with:
<b>Random rannum
if rannum=66535 then start ' get an even distrubution of odd and even numbers</b> because either way only the first four bits are going to be looked at anyway.
I used one LED per port on four ports that represented bits 0 to 3 that were generated.
Anyone have any idea what might be up with those long strings of 15? This did show me that I may need to include a routine to stop the same number from being generated twice in a row.
Overall I am quite pleased with myself. My test programs all eventually worked as planned after I did more reading. I compiled them on the free online demo version and now I think I will download the pbc so I can work on the bigger final program.
Thanks for the help to this point!
Bart
-
I did a spread analysis when I first came up with results like yours... however, after taking 65535 samples and analysing the results, I discovered that the spread is pretty equal over a much larger sample. There's no guarantee you'll get heads or tails an equal number of times flipping a quarter within a small sample quantity, but they'll pretty much ballance given a large enough sample. Remember your 'Probability' lessons back in Math at school.
-
That class was many, MANY years ago!
I did a bit more tweaking last night and added a routine to eliminate back to back duplicates. That smoothed things out quite a bit. I did get some interesting "patterns" however. The sequence 11 - 7 - 15 - 14 came up quite a bit, but the overall string itself was far more "random" - at least enough for what I need. I think I can safely move on to debugging the next part of the code.
Bart
-
You can implement a cellular automata, in the micro. There are some examples on the net in order to generate a pseudo random numbers using this method.
I used a long time ago, in an AI course.