Random number generation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chud
    Swordsman
    • Jun 2010
    • 309

    Random number generation?

    Is the random number generation in Angband just the standard rand() from the C library?

    A couple of things make me wonder... one from cheating, yes, it's true; I copied a save file for a character with 0 HP (note: still alive...) and poisoned... and since she had only one healing option, the actions from run to run were always the same (hit, miss, hit, breathe, etc) because my (healing) action was always the same. If the seed to rand() is stored in the save file, that makes sense.

    The other thing that makes me wonder is that sometimes spell failure rates seem... oddly distributed, shall we say. Like, 45% failure fails 7 times in a row. Sure, it could happen... but it makes you go "hmmm..." :-)



  • Derakon
    Prophet
    • Dec 2009
    • 9022

    #2
    Angband uses a custom RNG, and yes, the RNG state is saved to prevent savefile scumming. Someone did an analysis years ago comparing it to the Mersenne Twister, and it had comparable levels of randomness as far as I can recall. That said, it does seem odd how often I fail a 15% spell chance several times in a row, doesn't it?

    Comment

    • d_m
      Angband Devteam member
      • Aug 2008
      • 1517

      #3
      Originally posted by Derakon
      Angband uses a custom RNG, and yes, the RNG state is saved to prevent savefile scumming. Someone did an analysis years ago comparing it to the Mersenne Twister, and it had comparable levels of randomness as far as I can recall. That said, it does seem odd how often I fail a 15% spell chance several times in a row, doesn't it?
      If I remember, it's cycle is shorter than Mersenne Twister, but long enough that most people aren't going to notice (particularly with all the different unpredictable things we end up doing with entropy).
      linux->xterm->screen->pmacs

      Comment

      • Atarlost
        Swordsman
        • Apr 2007
        • 441

        #4
        Not sure why Angband never switched to Mersenne Twister on the principle that nobody ever got fired for buying IBM.
        One Ring to rule them all. One Ring to bind them.
        One Ring to bring them all and in the darkness interrupt the movie.

        Comment

        • takkaria
          Veteran
          • Apr 2007
          • 1951

          #5
          Originally posted by Derakon
          Angband uses a custom RNG, and yes, the RNG state is saved to prevent savefile scumming. Someone did an analysis years ago comparing it to the Mersenne Twister, and it had comparable levels of randomness as far as I can recall. That said, it does seem odd how often I fail a 15% spell chance several times in a row, doesn't it?
          Angband's RNG is far far less random then MT. We could change it, but it always seemed to be part of the character of the game to me.
          takkaria whispers something about options. -more-

          Comment

          • fizzix
            Prophet
            • Aug 2009
            • 3025

            #6
            Originally posted by takkaria
            Angband's RNG is far far less random then MT. We could change it, but it always seemed to be part of the character of the game to me.
            I think with the current display where probability of failing is shown outright, it would be better to reexamine this mindset.

            For example, a lot of times I make a calculation assuming independent events. I might say, I have a 5% chance of failing, so my chances of failing twice in a row is 1 in 400. This is an acceptable risk, so I'm going to attempt to cast the spell.

            Now if the probability of failing twice in a row was actually 1/100 or even 1/50, I would definitely consider another course of action.

            Comment

            • Chud
              Swordsman
              • Jun 2010
              • 309

              #7
              Originally posted by fizzix
              I think with the current display where probability of failing is shown outright, it would be better to reexamine this mindset.
              I have to agree here -- especially given that all the hardware Angband is going to be running on these days is so much faster than the earliest versions needed to work with; implementing a computationally expensive (relatively) RNG is no longer a practical problem.

              Or maybe it never was; I haven't looked at how fast the various RNG algorithms are these days--maybe this was never an issue, but in any case it can't possibly be today. And I'd really rather that a given percent chance was honestly presented in the game, if it's going to be presented at all. Bugginess to the contrary might add some character to the game, but in my opinion it's not the sort of character the game wants.

              Comment

              • takkaria
                Veteran
                • Apr 2007
                • 1951

                #8
                Originally posted by Chud
                I have to agree here -- especially given that all the hardware Angband is going to be running on these days is so much faster than the earliest versions needed to work with; implementing a computationally expensive (relatively) RNG is no longer a practical problem.

                Or maybe it never was; I haven't looked at how fast the various RNG algorithms are these days--maybe this was never an issue, but in any case it can't possibly be today. And I'd really rather that a given percent chance was honestly presented in the game, if it's going to be presented at all. Bugginess to the contrary might add some character to the game, but in my opinion it's not the sort of character the game wants.
                Alright, well, does anyone actually object to making the RNG closer to random? If not, we can make it happen...
                takkaria whispers something about options. -more-

                Comment

                • Magnate
                  Angband Devteam member
                  • May 2007
                  • 5110

                  #9
                  Originally posted by takkaria
                  Alright, well, does anyone actually object to making the RNG closer to random? If not, we can make it happen...
                  How much work is it? If it's a simple drop-in replacement for z-rand.c then I'm all for it - but I wouldn't have thought this was a top priority for anybody, since z-rand.c has served us well enough for however many years. But you're the boss .... ;-)
                  "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

                  Comment

                  • d_m
                    Angband Devteam member
                    • Aug 2008
                    • 1517

                    #10
                    I just received permission from Pierre L'Ecuyer to use his team's WELL1024a.c implementation in Angband. It uses 1024 bits of state and should perform well for us (better than Mersenne Twister).

                    It will be a change that could break savefiles, however I think it should be possible to detect and update people's saved seed (which has far too few bits).

                    So to answer Magnate's question, it should not require too much work at all
                    linux->xterm->screen->pmacs

                    Comment

                    • buzzkill
                      Prophet
                      • May 2008
                      • 2939

                      #11
                      I've no idea what most of that means, but I'm excited about the change.
                      www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012.
                      My banding life on Buzzkill's ladder.

                      Comment

                      • Chud
                        Swordsman
                        • Jun 2010
                        • 309

                        #12
                        Someone asked a bit ago "how big a deal is this?" -- not very big, really, but *if* it's not difficult to fix (and it sounds like it's not at all) then I would definitely prefer that the RNG be more really random(-like). Not a huge deal in the big picture... but, just one vote.

                        Comment

                        • takkaria
                          Veteran
                          • Apr 2007
                          • 1951

                          #13
                          Originally posted by d_m
                          I just received permission from Pierre L'Ecuyer to use his team's WELL1024a.c implementation in Angband. It uses 1024 bits of state and should perform well for us (better than Mersenne Twister).
                          Can we releease that under the GPL?
                          takkaria whispers something about options. -more-

                          Comment

                          • Tiburon Silverflame
                            Swordsman
                            • Feb 2010
                            • 405

                            #14
                            Looks like it.

                            Comment

                            • d_m
                              Angband Devteam member
                              • Aug 2008
                              • 1517

                              #15
                              Originally posted by Tiburon Silverflame
                              The page you're linking to actually uses a different license in the source files:

                              Code:
                              /* ***************************************************************************** */
                              /* Copyright:      Francois Panneton and Pierre L'Ecuyer, University of Montreal */
                              /*                 Makoto Matsumoto, Hiroshima University                        */
                              /* Notice:         This code can be used freely for personal, academic,          */
                              /*                 or non-commercial purposes. For commercial purposes,          */
                              /*                 please contact P. L'Ecuyer at: lecuyer@iro.UMontreal.ca       */
                              /* ***************************************************************************** */
                              I did write the authors and get specific permission to use it in Angband under the GPL, but the files they ended up posting to a different website under the GPL used version 3.

                              Since I specifically asked and got permission for Angband I am going to include it in my tree, but I'm also going to write to them for clarification and if they say GPL-3 is the only GPL they'll allow then we'll maybe have to do something else.
                              linux->xterm->screen->pmacs

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎