Modding, Mission Design, and Coding > The FRED Workshop

What's a "seed" in "rand"?

(1/2) > >>

TopAce:
Can you explain to me, in simple English, what a "seed" is as optional third value of "rand"?

I tried several different variations and I learned only two things: the higher the number, the closer it will be to the minimum number, and when a seed is set, the engine will not randomize anything - I get the same number with the given seed all the time. My attempts were in the range of 10 and 30 with seeds from 10 to 200.

Let me emphasize the phrase simple English. The explanations that I found with Google are pure technobabble that I could follow until the third word.

Better, can you give an example and explain what that event does and why? A theoretical one would be as good as one that was actually used in a campaign.

JSRNerdo:

--- Quote from: TopAce on December 02, 2020, 03:03:44 am ---I tried several different variations and I learned only two things: the higher the number, the closer it will be to the minimum number, and when a seed is set, the engine will not randomize anything - I get the same number with the given seed all the time.

--- End quote ---

Your second observation is correct - when you put in a seed of 444444, and then ask for 5 numbers between 1 and 100, you will always get 44, 56, 18, 2 and 87 (numbers made up for example only, actual results may vary). Your first is incorrect - how big the seed number is has nothing to do with how big the numbers you get are.

Think of the RNG as a box with a million different strings of numbers.

When you pick a seed, you always get that specific string, and when you ask for random numbers you always get the numbers in that string in order.
When you don't pick a seed, you pick one out at random and get a different result every time (hopefully).

The E:
TL;DR: You usually do not need to bother setting the random seeds unless you have something very specific in mind.

To explain, let's look at how an RNG like the one used in FSO works. The first thing to know about them is that they are pseudorandom: If you keep asking for random numbers by invoking rand, you get a series of numbers that at first glance will appear random. However, they are not: These numbers are generated by performing an operation on an initial value (this is usually the computer's clock, but can be set manually), which we call the seed value. Meaning that, if you know the seed value, you can predict the series of numbers the RNG generates with perfect accuracy.
Now, in FSO's case, there is only one, global, RNG for the entire engine. When you use rand with a seed value, you are resetting the global RNG: This means that, from that point forward, the RNG will behave deterministically. In the absence of player actions forcing different outcomes, the AI behaviour will be largely predictable as the output of any random operation in the engine becomes predictable.
This can be useful in some edge cases, like making sure that the AI always behaves the same during a cutscene, but for the most part isn't something you need to bother with.

Assassin714:

--- Quote from: The E on December 02, 2020, 04:01:42 am ---TL;DR: You usually do not need to bother setting the random seeds unless you have something very specific in mind.

To explain, let's look at how an RNG like the one used in FSO works. The first thing to know about them is that they are pseudorandom: If you keep asking for random numbers by invoking rand, you get a series of numbers that at first glance will appear random. However, they are not: These numbers are generated by performing an operation on an initial value (this is usually the computer's clock, but can be set manually), which we call the seed value. Meaning that, if you know the seed value, you can predict the series of numbers the RNG generates with perfect accuracy.
Now, in FSO's case, there is only one, global, RNG for the entire engine. When you use rand with a seed value, you are resetting the global RNG: This means that, from that point forward, the RNG will behave deterministically. In the absence of player actions forcing different outcomes, the AI behaviour will be largely predictable as the output of any random operation in the engine becomes predictable.
This can be useful in some edge cases, like making sure that the AI always behaves the same during a cutscene, but for the most part isn't something you need to bother with.

--- End quote ---

Sounds like it could be useful for testing/debugging purposes. If you have a random event with multiple possible outcomes, you can test each one in order instead of just playing the mission over and over again and hoping you get all of the possible outcomes.

The E:
I mean, that's usually easier to do by hardcoding the path you want to test, but that is certainly something you could do.