Changes between 1.10s and 1.10
#91
vor_lord,Nov 9 2003, 10:26 AM Wrote:There have been a lot of indications that positioning affects random number rolls (at least back in the classic days), so I don't think they are using a standard call anyway.  I'd guess their implementation avoids floats altogether.  Were you perhaps referring to a 'standard/classic' algorithm?  They may in fact be using something like that.  Which one exhibits 2-point correlation in particular?

Are there any knowledgeable modders that can help here?  Maybe some true CS guys?

EDIT:  By true CS guys I mean as contrasted with myself as an electrical engineer who codes for a living.  I don't mean to say that Ferengi is not a 'true' CS guy.
They do not use a standard call as that could yield different results on different hardware platforms (Intel, AMD, Macs, etc.) depending on how they each implemented such a thing at the processor level. The PRNGs that are used in multiplayer games must stay in synch or it will start giving each of the players different results in the same game, and then who is right?

The system in Diablo2 is mostly integer calculations except in a few small sections of code. For the PRNGs in the game they are using 2 DWORDs for handling this. Here is a better listing that I save from some time ago.

Quote:Jarulf made a post on the Amazon basin outlining the random number generator. Relevant portion:
In reply to:

>If the number generator was written by Blizzard, this contradicts your first assertion and is indeed a critical
>point in this discussion. If it is not written by Blizzard and not a component of the C runtime library, how can
>you assert that it is not flawed?

As far as I know, the one used in D2 should not be "invented" or written by Blizzard themselves. BY the way, it works like this (the exact explanation may depend on how one view the data, 2 32 bit values can be seen as a 64 bit value for example. I like to view it as two separate 32 bit values though.

Each seed is made up of 2 32 bit values (or one may see them as 1 64 bit value). I will call it seed_lo and seed_hi.

Next, an intermediate value (64 BIT!!!) is calculated as:

seed_lo * 0x6ac690c5 + seed_hi

Note, it will "roll over" if above max value for an unsigned 64 bit value.

The upper 32 bits are stored away as the new seed_hi while the lower 32 bits are stored away as seed_lo. In addition the lower 32 bits (the new seed_lo) is used to generate the random number through a mod division:

random number = seed_lo mod X

Thus generating an integer value in the range from 0 to X-1

The game will always when needing a random value, thus do a Rnd[X] which will return a value in the range 0 to X-1. If one need a value in the range Y to Z, one have to do Y + Rnd[Z-Y+1]. Here we have the reason for the off by 1 bug found in pre 1.08 version of Diablo 2. Where affixes and properties of an item like AC could never have its maximum value, the programmer forgot the +1 and used Y + Rnd[Z-Y]. This has been fixed for most cases but last I checked not for AC and possibly for things like number of arrows in a quiver and such, have not checked each case, I have informed Blizzard about it though. The same bug actually existed in several other places, like damage calcs. Since they used higher precision through fixed point arithmetic, the errors was only 1/256 of a damage point, which for practical purposes is neglectable but still exist in the game, that is, if your weapon do a maximum of 50 damage, the most you can do is 49 + 255/256 of a point. Since selecting items from a list and such only uses random values from 0 up to X, this should not happen.

Feel free to do whatever tests there can be done on this random number generator. By the way, when the seed is initialized, it is always made so that seed_hi has the value of 0x0000029a, while seed_lo can get whatever "random" number one want, initially for example based on some time stamp. The algorithm will never, if seeded correctly with 0x29a and a non 0 seed_lo, reach a state where seed_lo and seed_hi are 0 (since then from then on it would definitely not randomize any more ).

From my looking at the process I have not seen any indication that the "successive numbers strongly tend to be the same" as Ferengi puts it. In fact comparing this to several of the PRNG algorithms that I have found on the net (that are considered to be about as could as you can get without resorting more than 64 bits), this one is very similar in form and function. Considering the number of times that it is called at some points in the game, it is probably an adaptation that has been optimized for the speed at the reduction of some of the factors in the other PRND that would not be getting exploited. (Keeping in mind that a server will be running up to 128 games simultaneously.)
Reply


Messages In This Thread
Changes between 1.10s and 1.10 - by MongoJerry - 10-29-2003, 01:23 AM
Changes between 1.10s and 1.10 - by Guest - 10-29-2003, 01:53 AM
Changes between 1.10s and 1.10 - by adeyke - 10-29-2003, 02:00 AM
Changes between 1.10s and 1.10 - by MongoJerry - 10-29-2003, 02:31 AM
Changes between 1.10s and 1.10 - by mattis - 10-29-2003, 03:41 AM
Changes between 1.10s and 1.10 - by Guest - 10-29-2003, 04:01 AM
Changes between 1.10s and 1.10 - by mattis - 10-29-2003, 04:54 AM
Changes between 1.10s and 1.10 - by adeyke - 10-29-2003, 05:35 AM
Changes between 1.10s and 1.10 - by MongoJerry - 10-29-2003, 08:43 AM
Changes between 1.10s and 1.10 - by Crystalion - 10-29-2003, 11:06 AM
Changes between 1.10s and 1.10 - by Guest - 10-29-2003, 11:52 AM
Changes between 1.10s and 1.10 - by mattis - 10-29-2003, 01:29 PM
Changes between 1.10s and 1.10 - by Nicator - 10-29-2003, 02:07 PM
Changes between 1.10s and 1.10 - by adeyke - 10-29-2003, 02:16 PM
Changes between 1.10s and 1.10 - by adeyke - 10-29-2003, 02:18 PM
Changes between 1.10s and 1.10 - by Raziel - 10-29-2003, 02:25 PM
Changes between 1.10s and 1.10 - by Nicator - 10-29-2003, 03:00 PM
Changes between 1.10s and 1.10 - by MongoJerry - 10-29-2003, 06:48 PM
Changes between 1.10s and 1.10 - by Guest - 10-29-2003, 07:52 PM
Changes between 1.10s and 1.10 - by GenericKen - 10-30-2003, 12:02 AM
Changes between 1.10s and 1.10 - by Crystalion - 10-30-2003, 04:21 AM
Changes between 1.10s and 1.10 - by TheDragoon - 10-30-2003, 05:32 AM
Changes between 1.10s and 1.10 - by Pren - 10-30-2003, 01:25 PM
Changes between 1.10s and 1.10 - by TheDragoon - 10-30-2003, 07:52 PM
Changes between 1.10s and 1.10 - by Pren - 10-30-2003, 08:57 PM
Changes between 1.10s and 1.10 - by Ruvanal - 10-30-2003, 10:47 PM
Changes between 1.10s and 1.10 - by TheDragoon - 10-30-2003, 11:53 PM
Changes between 1.10s and 1.10 - by MongoJerry - 11-01-2003, 12:56 AM
Changes between 1.10s and 1.10 - by jahcs - 11-01-2003, 01:36 AM
Changes between 1.10s and 1.10 - by adeyke - 11-01-2003, 01:46 AM
Changes between 1.10s and 1.10 - by Guest - 11-01-2003, 02:06 AM
Changes between 1.10s and 1.10 - by LucianDK - 11-01-2003, 10:48 AM
Changes between 1.10s and 1.10 - by south - 11-01-2003, 12:10 PM
Changes between 1.10s and 1.10 - by Crystalion - 11-01-2003, 12:56 PM
Changes between 1.10s and 1.10 - by Hammerskjold - 11-01-2003, 03:01 PM
Changes between 1.10s and 1.10 - by Guest - 11-01-2003, 03:16 PM
Changes between 1.10s and 1.10 - by schizoidmime - 11-01-2003, 05:04 PM
Changes between 1.10s and 1.10 - by GenericKen - 11-01-2003, 10:07 PM
Changes between 1.10s and 1.10 - by Guest - 11-01-2003, 11:31 PM
Changes between 1.10s and 1.10 - by Crystalion - 11-02-2003, 05:53 AM
Changes between 1.10s and 1.10 - by adeyke - 11-02-2003, 06:39 AM
Changes between 1.10s and 1.10 - by Guest - 11-02-2003, 04:59 PM
Changes between 1.10s and 1.10 - by Guest - 11-02-2003, 05:10 PM
Changes between 1.10s and 1.10 - by TheDragoon - 11-02-2003, 08:34 PM
Changes between 1.10s and 1.10 - by Brista - 11-03-2003, 01:57 AM
Changes between 1.10s and 1.10 - by adeyke - 11-03-2003, 02:08 AM
Changes between 1.10s and 1.10 - by MongoJerry - 11-03-2003, 02:18 AM
Changes between 1.10s and 1.10 - by Ruvanal - 11-03-2003, 02:30 AM
Changes between 1.10s and 1.10 - by Epi - 11-03-2003, 08:00 AM
Changes between 1.10s and 1.10 - by Occhidiangela - 11-03-2003, 08:30 PM
Changes between 1.10s and 1.10 - by Occhidiangela - 11-03-2003, 08:34 PM
Changes between 1.10s and 1.10 - by Velius - 11-04-2003, 06:44 AM
Changes between 1.10s and 1.10 - by MongoJerry - 11-04-2003, 08:14 AM
Changes between 1.10s and 1.10 - by Walkiry - 11-04-2003, 10:20 AM
Changes between 1.10s and 1.10 - by Guest - 11-04-2003, 04:32 PM
Changes between 1.10s and 1.10 - by Bhima - 11-04-2003, 05:38 PM
Changes between 1.10s and 1.10 - by Crystalion - 11-04-2003, 07:40 PM
Changes between 1.10s and 1.10 - by MongoJerry - 11-04-2003, 07:49 PM
Changes between 1.10s and 1.10 - by Guest - 11-04-2003, 08:02 PM
Changes between 1.10s and 1.10 - by librarian - 11-05-2003, 12:20 AM
Changes between 1.10s and 1.10 - by Velius - 11-05-2003, 02:12 AM
Changes between 1.10s and 1.10 - by librarian - 11-05-2003, 02:51 AM
Changes between 1.10s and 1.10 - by Bhima - 11-05-2003, 04:52 PM
Changes between 1.10s and 1.10 - by AssA - 11-05-2003, 08:15 PM
Changes between 1.10s and 1.10 - by Crystalion - 11-05-2003, 09:39 PM
Changes between 1.10s and 1.10 - by Brista - 11-05-2003, 09:45 PM
Changes between 1.10s and 1.10 - by MongoJerry - 11-06-2003, 01:46 AM
Changes between 1.10s and 1.10 - by Crystalion - 11-06-2003, 04:04 AM
Changes between 1.10s and 1.10 - by Flymo - 11-06-2003, 03:50 PM
Changes between 1.10s and 1.10 - by Olon97 - 11-06-2003, 06:54 PM
Changes between 1.10s and 1.10 - by Guest - 11-06-2003, 07:08 PM
Changes between 1.10s and 1.10 - by Brista - 11-06-2003, 07:11 PM
Changes between 1.10s and 1.10 - by Guest - 11-06-2003, 07:13 PM
Changes between 1.10s and 1.10 - by par_deus - 11-06-2003, 07:14 PM
Changes between 1.10s and 1.10 - by Brista - 11-06-2003, 08:16 PM
Changes between 1.10s and 1.10 - by Crystalion - 11-06-2003, 08:30 PM
Changes between 1.10s and 1.10 - by librarian - 11-07-2003, 12:23 AM
Changes between 1.10s and 1.10 - by librarian - 11-07-2003, 12:45 AM
Changes between 1.10s and 1.10 - by GenericKen - 11-07-2003, 12:54 AM
Changes between 1.10s and 1.10 - by MongoJerry - 11-07-2003, 03:10 AM
Changes between 1.10s and 1.10 - by Smoketest - 11-08-2003, 08:15 PM
Changes between 1.10s and 1.10 - by Guest - 11-08-2003, 10:22 PM
Changes between 1.10s and 1.10 - by Baal - 11-09-2003, 02:22 AM
Changes between 1.10s and 1.10 - by pmpch - 11-09-2003, 03:06 AM
Changes between 1.10s and 1.10 - by Ferengi - 11-09-2003, 01:01 PM
Changes between 1.10s and 1.10 - by Ferengi - 11-09-2003, 01:12 PM
Changes between 1.10s and 1.10 - by Ferengi - 11-09-2003, 01:26 PM
Changes between 1.10s and 1.10 - by vor_lord - 11-09-2003, 02:35 PM
Changes between 1.10s and 1.10 - by Ruvanal - 11-09-2003, 04:54 PM
Changes between 1.10s and 1.10 - by MongoJerry - 11-09-2003, 05:46 PM
Changes between 1.10s and 1.10 - by Aello - 03-13-2004, 03:06 AM
Changes between 1.10s and 1.10 - by Obi2Kenobi - 03-14-2004, 04:59 PM
Changes between 1.10s and 1.10 - by Aello - 03-15-2004, 08:17 AM
Changes between 1.10s and 1.10 - by Jarulf - 03-15-2004, 01:57 PM
Changes between 1.10s and 1.10 - by adeyke - 03-15-2004, 03:33 PM
Changes between 1.10s and 1.10 - by Ruvanal - 03-15-2004, 09:12 PM
Changes between 1.10s and 1.10 - by Aello - 03-16-2004, 12:38 AM
Changes between 1.10s and 1.10 - by Jarulf - 03-16-2004, 06:14 AM
Changes between 1.10s and 1.10 - by lemekim - 03-16-2004, 07:55 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)