1, the linear congruential random number algorithm (LGC) |
---|
Formula: X n- = (Ax of [n--. 1] + B)% M A: Multiplier B: increment M: maximum value of X [n--. 1] : Seed connection: https://www.cnblogs.com/forget406 /p/5294143.html |
achieve:
int[] x;
private void Random(int seed, int max)
{
x = new int[max];
int A = 9;
int B = 7;
//初始化种子
x[0] = seed;
for (int i = 1; i < max; i++)
{
x[i] = (A * x[i - 1] + B) % max;
Debug.Log(x[i]);
}
}