Answer the question
In order to leave comments, you need to log in
How to make different random generators?
Let's say at the beginning of the game each time a map is generated.
Generation depends on randomness.
To make the generation repeatable, the same seed is used at the beginning of the generation.
For example, after generation, entity damage is dealt, depending on randomness, and this damage will be the same every time, because. seed was used before generation.
Example:
Random.InitState(10);
for (int i = 0; i < 3; i++)
{
Debug.Log($"GENERATION : {Random.Range(0f, 1f)}");
}
for (int i = 0; i < 3; i++)
{
Debug.Log($"SHOOT : {Random.Range(0f, 1f)}");
}
Вывод каждый раз одинаковый:
GENERATION : 0.2686557
GENERATION : 0.7817978
GENERATION : 0.9014543
SHOOT : 0.3051965
SHOOT : 0.8728517
SHOOT : 0.2956414
var shootSeed = Random.Range(int.MinValue, int.MaxValue);
Random.InitState(10);
for (int i = 0; i < 3; i++)
{
Debug.Log($"GENERATION : {Random.Range(0f, 1f)}");
}
for (int i = 0; i < 3; i++)
{
Random.InitState(shootSeed);
Debug.Log($"SHOOT : {Random.Range(0f, 1f)}");
shootSeed = Random.Range(int.MinValue, int.MaxValue);
}
Выводы:
1)
GENERATION : 0.2686557
GENERATION : 0.7817978
GENERATION : 0.9014543
SHOT : 0.4784655
SHOT : 0.2666625
SHOT : 0.5826535
2)
GENERATION : 0.2686557
GENERATION : 0.7817978
GENERATION : 0.9014543
SHOT : 0.7529675
SHOT : 0.8416272
SHOT : 0.09183574
и т.д.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question