RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

True Random

pepolshet

Sorceror
Hey! So I've been playing around with the RunUO source files and decided to experiment with the random functions so I have swapped the normal random with a stronger RNGCryptoServiceProvider (.NET 4.5).

This makes the world a little bit more random and engaging, by what little I've tested it I've noticed my characters damage has dropped dramatically because I've been quite unfortunate apparently, this addresses the predictable nature of random.

I've got the idea when playing an old sphere server, the users could estimate how much ingots they would get by the time their mining reaches 100. Keep in mind that I'm just playing around and it's on your responsibility if your shard should crash or anything else, this random function is about 200 times slower than the old random function so performance issues should be taken into account even though I personally think most servers could handle it without a problem.
 

Attachments

  • source.zip
    513.5 KB · Views: 8
  • random.zip
    227.9 KB · Views: 10

pepolshet

Sorceror
Just noticed the title might be misguiding, this still isn't "true random", we wouldn't use a computer to achieve "true random" at all, we would measure radiation decay instead or something like that.
 

_Epila_

Sorceror
I am not a physicist nor a scientist, but I like to think that there is no absolute real random, even on nature, i mean, if you place an egg on top of a mountain, perfectly balanced with no external influences acting on it, it will roll left or right? If it is perfectly balanced there is no reason to roll. Taking the radiation decay example, the decay appear to be random, since you can not not precisely measure (I mean, true absolute measure / 1/3 != 0.3333 periodic) the nucleon/electrons positions, energy and other proprieties, you can not predict when it will decay. From my point of view, physics (or nature) is mathematically perfect, the problem is that there is no way to have an absolute precisely measurement of anything (may be in a near future will have?). So we call this "unknown part" of the measurements as random. This may be one of the reasons we use Significant Figures in our calculations.
Thinking this way implies that we (and the whole universe) is bound to a precisely described, that conflicts against other thought about our (at leat mine :p) lives; that we can "write" our destination, since we can choose (we are conscious right?) what to or not to do. (Determinism against Free-will)

Random.org made an almost "true random" by checking the atmospheric variations and generating "random" numbers based on the "readings" of the atmosphere. Using it with RunUO is out of question, since you can not simply attach some kind of atmospheric reader gadget or ask the website to give the numbers, but taking this as an example, you can read the computer environment variables (input voltage, time since started, clock, *temperature, *fan speed, even the microphone if you have one attached to your server hardware) right? Don't know about the performance but this is my initial thoughts about computational random numbers.

True randomness means that if R is the set of the possible values that R={a1,a2,...,an} with n elements, for every value you have a P(ai)=1/n for i=[1,n]. To check if the value can be selected by the time you request the next R value, you have to check (following statistical definitions) if (P(ai) < S()), which S is the random function with Im(S):[0,1], that come back to the R set and on and on....
If S is the random function, it can be described as an infinite recursive function
Note that S can not receive any argument, as it can not depend of any initial state in order to match the true randomness

This may not be a solid argument (yeah, there are a lot of things that I simply ignored/skipped), but it is my immediate (and scrambled) thoughts.
There are a lot of things we could write about randomness but it is and incredible long discussion.


Merlijn (from Sciforums.com) said:
I believe that absolute randomness means copletely independent of initial state.
If V signifies the set of all possible outcomes and V={X1, X2, ...,Xn} then P(X1)=P(X2)=....=P(Xn)=1/n, whatever the initial state.

If I am correct, there is no issue other than that we are probably not able to ever create a system that is independent of its initial state. Thus it will be an ideal impossible to reach.


I have never noticed an predictable pattern provided by the original C# random function. Some months ago, I was curious about how the computational random works and did some checks, even used the Benford's Law to check the values. The result was that


Anyway, thanks for sharing. :)


Random Visual Patterns
PHP Rand() on Windows
C# (.NET) Random
 

Pure Insanity

Sorceror
Aye, true random in computer is almost impossible. Unless you have a laboratory that measures radioactive decay or something like was mentioned above. Good proof of concept of random being fallible, is the harvest system for RunUO. If all public shards were to restart, you could log onto each one. Find the same spot on each shard, and the same type of ore will spawn in that vein after restart. On ALL shards, the ore will spawn the same in the same area.
 

Shino90

Sorceror
Good proof of concept of random being fallible, is the harvest system for RunUO. If all public shards were to restart, you could log onto each one. Find the same spot on each shard, and the same type of ore will spawn in that vein after restart. On ALL shards, the ore will spawn the same in the same area.
Ore veins are intentionally the same on pre-ML shards, because ore veins never changed in those eras on official shards.

Mining.cs:
Code:
oreAndStone.RandomizeVeins = Core.ML;

HarvestDefinition.cs:
Code:
        public HarvestVein GetVeinAt( Map map, int x, int y )
        {
            if ( m_Veins.Length == 1 )
                return m_Veins[0];
 
            double randomValue;
 
            if ( m_RandomizeVeins )
            {
                randomValue = Utility.RandomDouble();
            }
            else
            {
                Random random = new Random( ( x * 17 ) + ( y * 11 ) + ( map.MapID * 3 ) );
                randomValue = random.NextDouble();
            }
 
            return GetVeinFrom( randomValue );
        }

The seed being used for the Random object is what produces the same values. Change the seed (add 1 to it, for example), change the numbers. ;)

The randomized veins would only be the same on different shards if Utility's Random object was instantiated at the exact same tick counts on all servers and with the exact same random calls before you reach your vein. Extremely unlikely.
 

pepolshet

Sorceror
I have never noticed an predictable pattern provided by the original C# random function. Some months ago, I was curious about how the computational random works and did some checks, even used the Benford's Law to check the values. The result was that


Anyway, thanks for sharing. :)


Random Visual Patterns
PHP Rand() on Windows
C# (.NET) Random

I am not educated in the field of cryptography but from what I understand the seed that is used for the RNGCryptoServiceProvider is provided using various system and user data such as the process ID, thread ID, system clock, system time, system counter, memory status, free disk clusters, hashed user environment block along with international standard cryptography algorithms and internal computer temperature sensors. It is certainly a lot more chaostic than the plain old random.

If I would build an application that would select a random number from 1 to 10 100,000 times every number would fall about 10,000 times (I say about because it won't be exact due to rounding errors with the seed and the algorithm actually being a little "random" due to other reasons) in contrary to the real world, in the real world any number could fall any number of times, you could theoretically get the number "2" just 1 time even though the chance is miniscule.

In other words if you would use a less psuedorandom algorithm such as the RNGCryptoServiceProvider the noise wouldn't be distributed as evenly in your second link, with a physical RNG the noise wouldn't be distributed evenly at all there would be spots with no noise at all and spots with a lot of noise. Thus the conclusion that an Ultima Online shard with true random would have a much more engaging gameplay because it would resemble the real world.
 
Top