Shop OBEX P1 Docs P2 Docs Learn Events
Random number in PASM - Page 2 — Parallax Forums

Random number in PASM

2»

Comments

  • Ahle2Ahle2 Posts: 1,179
    edited 2009-12-17 11:17
    lonesock said...

    BTW, I found that adding "ror random,random" at the end made for a better distribution, specially if you accidentally start out with a seed of 0. (note: ROR will internally AND the rotation value with 31.) There are still certain bands that seem more likely to come up (with 25,000 values plotted), but to me this version looks a bit better than the original 2-instruction version.
    Jonathan
    Yeah I realized that too... but it wasn't good for my emulator though because the random generation becomes "too good" compared to a real SID. wink.gif

    BTW, have you any statistics on how good the random generation is?

    Post Edited (Ahle2) : 12/17/2009 1:35:00 PM GMT
  • lonesocklonesock Posts: 917
    edited 2009-12-17 18:39
    Well, I ran Ent on some resulting data sets, and your original function has better distributions than with the added 3rd instruction.
    (www.fourmilab.ch/random/, though it's not overly state of the art...the NIST tests would be better wink.gif

    add/ror:
    Entropy = 7.999992 bits per byte.
    
    Optimum compression would reduce the size
    of this 40000000 byte file by 0 percent.
    
    Chi square distribution for 40000000 samples is 456.91, and randomly
    would exceed this value less than 0.01 percent of the times.
    
    Arithmetic mean value of data bytes is 127.5014 (127.5 = random).
    Monte Carlo value for Pi is 3.141500714 (error 0.00 percent).
    Serial correlation coefficient is -0.000192 (totally uncorrelated = 0.0).
    



    add/ror/ror:
    Entropy = 7.950003 bits per byte.
    
    Optimum compression would reduce the size
    of this 40000000 byte file by 0 percent.
    
    Chi square distribution for 40000000 samples is 2905248.42, and randomly
    would exceed this value less than 0.01 percent of the times.
    
    Arithmetic mean value of data bytes is 129.4133 (127.5 = random).
    Monte Carlo value for Pi is 3.130604713 (error 0.35 percent).
    Serial correlation coefficient is -0.005053 (totally uncorrelated = 0.0).
    



    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
Sign In or Register to comment.