Random number results


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189

    Exclamation 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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    seinfield's Avatar
    seinfield Guest


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. Random number seed
    By kwelna in forum mel PIC BASIC
    Replies: 10
    Last Post: - 1st February 2007, 17:33
  3. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 17:50
  4. Searches
    By bearpawz in forum Forum Requests
    Replies: 11
    Last Post: - 7th November 2005, 18:47
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts