1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. While the majority of active discourse on D20PRO has moved to our Discord Channels, this forum is still active and checked-in on regularly by our staff. However, for the very latest information, conversation and/or immediate support, please join us on Discord here: http://discord.gg/Ph38ckM
    Dismiss Notice

Pseudorandom numbers not so random

Discussion in 'Bug Reports & Installation Support' started by mercury00, Apr 14, 2011.

  1. mercury00

    mercury00 New Member

    Joined:
    Aug 9, 2010
    Messages:
    55
    Likes Received:
    0
    I have a bit of a bug in our game that's upsetting my players quite a bit. It's the dice rolls.

    I know. Java (or some library its using) makes it's pseudorandom numbers and on average they're - well, random. But we've noticed some rolls that just don't *look* quite as random as we would expect. Such as (rolling several d20 successively)

    1,1,3,1,2,3,2,1,20,4,20,1,19,17,19,9,5,2,1,2,1,1,13,20,13,15,18,14,18...

    along those lines - 1s or 2s or 3s will sometimes repeat (which is fine, that happens irl), but they'll happen all grouped up - so with the law of large numbers, everything looks good but in the short term things are odd. Does that make sense? Imagine flipping a coin and getting 10 heads in a row, then 10 tails in a row. The ratios you got were 50/50, but that's not really what we expect when we say random, right? Then well also see the ABA number pattern thing, like the (19,17,19). Which again, happens irl, but.. more often in d20pro?

    Yeah, it's a weird thing and I'm sure it's java, but, curious if there's *any* way I'd be able to affect it some. My players don't mind the 20 rolls so much (unless I'm making them), but they get annoyed rolling 4 or 5 1s in a row ;) In any case, even if I can't fix it I'd like to know if there's some magic step I can try that might convince my players it's *fixed*. Outside of reinstalling my OS (unless I really need to).

    Also, incidentially, I think there are 'true random' number generators in java (extra libraries) that might be better than the built-ins? Thanks.
     
  2. Daeruin

    Daeruin New Member

    Joined:
    Dec 24, 2010
    Messages:
    251
    Likes Received:
    1
    My players have complained about the same thing, one of them to the point where he almost wanted to quit the game. I would love to be able to show them it had been improved or fixed somehow.
     
  3. ogexam

    ogexam Member

    Joined:
    Jul 10, 2008
    Messages:
    526
    Likes Received:
    1
    I will do some data sets and look at them to see if the are trended in any way shape or form.

    I have not touched the code of our random number generator before, but I'll take a look under the hood. If you know of any "really good" random number generators that you suggest let me know.
     
  4. ogexam

    ogexam Member

    Joined:
    Jul 10, 2008
    Messages:
    526
    Likes Received:
    1
    I did a 500 d20 rolls. They averaged out to 10.414 which is almost statically perfect. Should be 10.5 if perfectly random.

    As for number of rolls per number
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    21 33 29 22 19 24 24 16 22 38 35 23 31 29 20 25 19 15 31 24

    In 500 rolls I got three more 20s then I did 1s. Though there does appear to be a hump around 10 and 11.

    I would need to do multiple runs of 500 to verify the trend.
     
  5. Daeruin

    Daeruin New Member

    Joined:
    Dec 24, 2010
    Messages:
    251
    Likes Received:
    1
    I think the original complaint was about variability on the short term - say runs of 10 to 50 rolls.
     
  6. Zandari

    Zandari New Member

    Joined:
    Sep 12, 2010
    Messages:
    46
    Likes Received:
    0
    Making complaints about random numbers based on a sample size of 10-20 rolls indicates a basic lack of understanding of statistics.
     
  7. ogexam

    ogexam Member

    Joined:
    Jul 10, 2008
    Messages:
    526
    Likes Received:
    1
    I did look for trends like a set of low and a set of high.

    I put them in a graph in excel and panned through them. While it would occur to have a few low at at time, so did it have a few mid and a few high in a row from time to time.

    This is statistically ok and expected.

    There did not appear to be any trends of "when X is rolled then all rolls for the next 3 only varied by Y which Y is small"
     
  8. mercury00

    mercury00 New Member

    Joined:
    Aug 9, 2010
    Messages:
    55
    Likes Received:
    0
    My players don't really care so much about the statistics as what they're repeatedly experiencing. If I were to roll ten 20's in a row, that would not be statistically insignificant. (In fact, the 'real' probability of getting this is 9.765625 × 10-14) That's a small sample size, and with just 10 rolls the odds of that happening are so low we don't have names for the decimal places in discussion.

    ogexam: Thanks for the good example, it proves what I'm saying about the numbers - the *total average* is good (pseudorandom number generators typically guarantee this), but look at the number of 10's vs. the number of 18s. You should not be getting a bell curve here, but a generally straight line. On any large scale (500 should be pretty good), you really, really shouldn't be getting twice the number of rolls of one dice than another - your expected value here is 25, and you're getting 38s and 15s.

    Which is bad, because my initial assumption was that the pseduorandom number generator java was implementing on my computer was bugged by my computer somehow. Your results make me think it's worse than that, I'm pretty sure java's included random library doesn't pass all the Marsaglia diehard tests.

    Regardless of all the above, there are better java pseudorandom number generators than the included libraries, such as javax.crypto.SecureRandom, which I think is slow.

    'Uncommon Maths' is supposed to have a good library? But I don't know what it is.

    Also, apparently someone's implemented Mersenne twister, http://www.cs.gmu.edu/~sean/research/

    This also looks like it could be a simple quick patch to slightly improve the numbers: http://www.javamex.com/tutorials/random ... hift.shtml This little trick would probably at least calm my players qualms.

    edited: removed the trolling flamey stuff
     
  9. ogexam

    ogexam Member

    Joined:
    Jul 10, 2008
    Messages:
    526
    Likes Received:
    1
    Thanks,

    Just need to verify about the copyright on that twist one, and see how to incorporate it into out system.
     
  10. mercury00

    mercury00 New Member

    Joined:
    Aug 9, 2010
    Messages:
    55
    Likes Received:
    0
    Sweet. I think theres a similar one here: http://www.math.sci.hiroshima-u.ac.jp/~ ... T-java.zip

    That one is free to use for commercial http://www.math.sci.hiroshima-u.ac.jp/~ ... ICENSE.txt, it kind of looks like it's a newer file - 2007 instead of 2004, but maybe it's not as easy to implement into the code, I dunno. Also, it's supposed to be a lot faster, at least the algorithm. The 2004 one seems to implement a lot of hacks to account for java limitations, but maybe thats a good thing, I dunno. Well hope that helps some.

    Also, d20pro is tops. No other software I've tried comes close to d20pros usability and features and such. Just thought I'd point that out.
     
  11. firebringer

    firebringer Member

    Joined:
    May 17, 2011
    Messages:
    88
    Likes Received:
    2
    Has there been any update or new information on this issue? My gaming group has used two different dice rollers (Hamete and iTableTop) and both of them seem to experience similar issues to what is described here. Having a robust and as-close-to-perfectly-random-as-possible dice roller is a big deal for us...

    Firebringer
     
  12. ogexam

    ogexam Member

    Joined:
    Jul 10, 2008
    Messages:
    526
    Likes Received:
    1
    Improving the random dice roller is on my list of improvements.
     
  13. firebringer

    firebringer Member

    Joined:
    May 17, 2011
    Messages:
    88
    Likes Received:
    2
    Thanks for the fast reply Ogexam...it totally kills the fun factor when the players and / or the GM don't have confidence that the dice roller is completely random. Here's hoping for good luck and fast turn around on your efforts!

    Firebringer
     

Share This Page