and Get3 A new Rand way, simple and practical.
The Gaussian distribution was random, filtered randomly, and perlin random, Perlin old friends, mainly said the first two.
Gaussian distribution stochastic (Gaussian randomness)The Gaussian distribution is also called normal (normal distribution) or bell-shaped (bell curves), and the normal distribution is familiar. It looks like this:
Why do we have to generate random according to the Gaussian distribution, we should mention a noun "central limit theorem". Central limit theorem: In Nature and production, some phenomena are affected by many independent random factors, if the influence of each factor is very small, the total influence can be regarded as obeying the normal distribution. The central limit theorem is a mathematical way of proving this phenomenon. In simple terms, the probability of randomness in real life is combined with a normal distribution. This is why we use the Gaussian distribution stochastic because the results are more realistic.
This stochastic based on Gaussian distribution can be used for: speed, human characteristics, then a forest of trees height, height, the deviation of firing bullets, and so on in nature common things.
Implementation code in Unity:
Using unityengine;using System.collections;public class gaussian:monobehaviour{public int seed = 61829450; Double sum = 0; Long r = 0; Use the for initialization void Start () { } //update is called once per frame void update () { if (time.framecount% 7== 0) { // seed = 61829450; sum = 0; for (int i = 0; i < 3; i++) { long holdseed = seed; Seed ^= seed <<; Seed ^= seed >>; Seed ^= seed << 5; r = holdseed + seed; Sum + = (double) R * (1.0/0X7FFFFFFFFFFFFFFF); } print (sum); Returns [ -3.0, 3.0] at (66.7%, 95.8%, 100%)}}
Pseudo random and Gaussian stochastic respectively simulate the deviation of shot bullets
Most of the points in the Gaussian distribution are in the center, the common pseudo-random distribution is more uniform, and the Gaussian distribution is more real. Players of course also want to be able to shoot, with a higher rate of headshot.
Use of Gaussian distribution:
1. Speed
2. Acceleration
3. Size, width, height, quality
4. Analog vision, reaction time
5. Bullet filling speed, firing speed
6. Refresh rate, Cooling rate
Filter Randomfilter random More emphasis on "fairness", that is, with the more chaotic is good. Filtering means that our random numbers are sometimes too close, or the gaps are too many to "filter" them off and re-randomly.
There is evidence that, when the random performance is very small, humans do not feel that this is random.
For example, many people do not believe that the result of tossing a coin is random, because the result you throw may be this:
There are plenty of repetitions of 00000 or 11111 close together. If you set the critical hit to random, the random result is that the enemy may be able to launch four or five critical hits to kill you directly, which is not what the player wants. But this is really random, so sometimes the fun of the player is more important than authenticity.
Binary filteringFiltering occurs in the following cases:
1. If the newly generated number already has four, re-randomly a new number
2. If 11001100, will be replaced by 11001101
3.111000 or 000111, replace the last number
Replace before substitution for comparison:
filter Integers1. There are two repeated random numbers, then the new random number is re-
2. Repetition of a number, such as "8, 3, 8" or "6, 2, 6"
3. Too many limit values appear, i.e. too many large values and small values such as "6, 8, 7, 9, 8, 6, 9"
4. There are two sets of repetitions within 10 numbers such as "5, 7, 3, 1, 5, 7"
5. Continuous rise, or continuous decline, such as "3, 4, 5, 6"
6. Excessive number of repetitions within 10 numbers, e.g. "9, 4, 5, 9, 7, 8, 9, 0, 2, 9"
Replace before substitution for comparison:
filtering floating point decimalsFloating-point number between 0-1
1. Two consecutive digits differ by less than 0.02, e.g. 0.875 and 0.856
2. Three consecutive digits differ by less than 0.1, such as 0.345, 0.421, and 0.387.
3. Five consecutive increments or successive drops, such as 0.342, 0.572, 0.619, 0.783, and 0.868.
4. Too many limit values appear, i.e. too many large and small values, 0.325, 0.198, 0.056, 0.432, and 0.216.
Summary
If you want to produce a more realistic result, you are using Gaussian distribution randomly. If you want to make the player happier, you can filter the resulting random number.
------by wolf96 http://blog.csdn.net/wolf96
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Advanced stochastic technology of game AI development