Random Number Generator

Discussion in 'General Modification' started by Shamshir, Dec 13, 2004.

Remove all ads!
  1. Shamshir

    Shamshir Member

    Joined:
    Nov 16, 2004
    Messages:
    6
    Likes Received:
    0
    Okay, wow.

    Last night, I finally took a look at the die-roll screen to figure out why I seemed to be performing so poorly in combat. I kept track of a fight with my level 5 party and a bunch of goblins with an Ogre in the upper level of the Earth Temple (they're in the kitchen.)

    I have been noticing that creatures and NPCs seem to be rolling far better than the player party, but then it got ridiculous. The first FIVE goblins that attacked all rolled natural 20's! Five critical hits in a row. Then the Ogre followed up with a 19. My characters' turn: Fighter with strength 18, Bull's Strength spell increasing it to 22, Bless, and Weapon specialization in Greatsword, granting +10 to hit--he rolls a natural 1! Then my Ranger, Dex 21, Blessed, weapon focus in Longbow, and natural enemies vs. Giants attacks the ogre using rapid shot--two attacks: natural 1, then a 3. The next three character all roll 6 or less. Goblins attack again, not a single one rolls less than a 16. The ogre--two attacks--ANOTHER natural 20 followed by a 19.

    It went on like this for four reload/replays. My characters typically rolled between 4-9 with an 4 critical hits 12 critical misses. The computer controlled characters typically rolled between 14-19. Seventeen--count'em critical hits and not ONE roll below 8.

    I tested this with some other saved games, older encounters, and while things weren't always so wildly unbalanced, the computer definitely made consistently better rolls at all times, and only missed two saving throws versus spells, with rolls of 2 and 5. EVERY OTHER SAVING THROW ROLL WAS A 19!

    It seems than the random number generator is...ah...scewed. Any thoughts on this?
     
  2. Lord Plothos

    Lord Plothos Established Member

    Joined:
    Apr 3, 2004
    Messages:
    550
    Likes Received:
    0
    I have certainly had similar experiences. I haven't kept track of the numbers in anything like the detail yo u have, but I certainly have the feeling that my enemies roll roughly three times the number of 20s I do, just for one example. I also feel like I roll a heck of a lot more 1s than I should. I have simply chalked this up to pessimism on my own part, though. It's human nature in this kind of situation to focus on the failures and take the successes for granted, especially when, as you say, you're getting +10s on every roll. That being said, I've still come to the same conclusion you have, the num gen is screwy. At the least, it seems streaky, a trait shared my the num gen of many a game, in my experience. On the other hand, that's just my impression, and the num gen actually being screwy is hardly the only thing that could explain why I feel as though it is.
     
  3. Lord Plothos

    Lord Plothos Established Member

    Joined:
    Apr 3, 2004
    Messages:
    550
    Likes Received:
    0
    Oh, and for some reason for about 20 or thirty tries, when my rogue attempted to start a fight by whacking an unprepared opponent, so as to get a cheap sneak attack, I roll a 1 about half the time. That was something I did document. 10 out of 20. Come on!
     
  4. Shamshir

    Shamshir Member

    Joined:
    Nov 16, 2004
    Messages:
    6
    Likes Received:
    0
    Where from here?

    Now that I know at least I'm not alone...

    I remember reading something a while back about the Random Number Generator used in the game being specifically designed to be modular or easily replaced or modified.

    Is there such a mod in existence?

    If not, what would it take to modify or recode the existing one? That seems like something I could tackle myself, but I'm still pretty ToEE-mod-dumb (and I know that d20 ramdomizers are not the easiest thing to create.) However, using a version of a d100 randomizer, and coding a simple "if/then" condition to "round" certain numbers to others (i.e.: a roll of 1-10="1", a roll of 11-20="2", etc.) might produce much more reliable and honest results.

    My feeling, howver, is that there is something in the game code itself that is weighing die rolls in the computer's favor (most likely to "increase the challenge" and "extend game-time" [because game developers are often so intelligent, creative, and resourceful in such ways.]) If that's the case, this may be hard-coded into the actual game engine...which would grieviously stink.

    Post away if you have info or recommendations.
     
  5. zhuge

    zhuge Established Member Veteran

    Joined:
    Sep 27, 2003
    Messages:
    484
    Likes Received:
    0
    The RNG before the 2nd official patch was known to be problematic and used to generate clumps of numbers. According to Steve Moret it previous RNG used the Quick and Dirty C++ RNG.
    The current RNG post 2nd official patch applies the Mersenne Twister which during our tests appear to generate more reasonable distributions.
    Make sure the 2nd official patch is properly applied.

    Try generating about 200 numbers from character generation rolls for checking purposes. You may hit certain 'bad' patches of rolls from time to time for 1d20 as the range is so wide. To be fair, try recording every d20 roll in combat from now on. Once you've recorded a fair number, make a post and we can make a comparison.
     
  6. Lord Plothos

    Lord Plothos Established Member

    Joined:
    Apr 3, 2004
    Messages:
    550
    Likes Received:
    0
    In keeping with that "just to be fair" line, I have noticed that the numbers seem a bit more reasonable after applying patch 2. The 10 out of 20 thing happened post patch 2, but in general it does seem better.
     
  7. Shamshir

    Shamshir Member

    Joined:
    Nov 16, 2004
    Messages:
    6
    Likes Received:
    0
    Random Rolls for characters coming up. (Sorry to everyone, but I'm not able to make it back to this site regularly.)

    Also, zhuge, thanks for that info. I still haven't taken the time to sit down and open up the nitty-gritty workings of the program, but at least I know what I'm looking for now. Does the Mersenne Twister still use C++, or is it its own program, or is it a mathematical formula...?...I have no idea what this is--I only mod games casually. (And I hate math. [But I looove broadswords!]) I also just did a reinstall of the game going directly to Patch 2. I've been running the same install since Patch 1 came out, so maybe the "Twister" was never properly installed over Patch 1.

    Okay, I'll be back sooner or later. Thanks for the help!
     
  8. Firestrand

    Firestrand Member

    Joined:
    Mar 11, 2004
    Messages:
    79
    Likes Received:
    0
    Sorry just wandered onto this thread and thought I would point people to info on the Mersenne Twister algorithm, more information can be found at
    The Mersenne Twister Home Page.

    The Mersenne Twister algorithm is a fast random number generator with a large period, that means that a repeated sequence of random values will only happen each period. The mersenne twister algorithm has a peiod of (2^19937)-1. The alsgorithm is of course language independent, I have seen java, c++, and c implimentations, but I am sure more exist. The algorithm is distributed via BSD licence, so you can use where ever you like.

    I hope that helps those interested.

    -Firestrand
     
Our Host!