Author Topic: What's a "seed" in "rand"?  (Read 945 times)

0 Members and 1 Guest are viewing this topic.

Offline TopAce

  • Stalwart contributor
  • 212
  • FREDder, FSWiki editor, and tester
What's a "seed" in "rand"?
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.
My community contributions - Get my campaigns from here.

I already announced my retirement twice, yet here I am. If I bring up that topic again, don't believe a word.

 

Offline JSRNerdo

  • [`_`]/
  • 29
  • King of Destroyer
Re: What's a "seed" in "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.

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).
AKA [`_`]
Inferno: It's the I in Inferno / It's the beam spam delight / Risin' up to a shock jump arrivaaaaaal
Between The Ashes: Look just a really cool and neat thing, OK?
Dimesional Eclipse: High speed anime girlies blowing **** up gets me excited
The Last Stand: A very episodic capship command mini-campaign
Breakthrough: A pretty standard but not really capship command mission

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: What's a "seed" in "rand"?
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.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: What's a "seed" in "rand"?
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.

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.
Shivans view most other species the way we view infectious diseases. They think they are doing good by curing the universe of them. After all, no one mourns the fate of smallpox.

The Final War For The Multiverse

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: What's a "seed" in "rand"?
I mean, that's usually easier to do by hardcoding the path you want to test, but that is certainly something you could do.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: What's a "seed" in "rand"?
I seem to remember that the reason the seed option was added was for exactly that reason. So that BHX could be deterministic and that if you were bug testing you knew which combination of factors were causing a bug to appear rather than having to re-hardcode everything in order have the bug happen every time.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: What's a "seed" in "rand"?
In the Feynmann tradition of simple English, here's my explanation:

The numbers aren't actually random.  As JSRNerdo said, they are specific sequences of numbers.  So imagine that the computer knows about several sequences, like this:

Sequence 1: 44, 56, 18, 2, 87
Sequence 2: 78, 5, 1, 99, 53
Sequence 3: 6, 34, 79, 44, 90
etc...

The "seed" is just the sequence identifier.  So in the above example, if you have a seed of 1, you will always get the sequence 44, 56, 18, 2, 87.  Any number you pick for a seed will correspond to some sequence, but the sequence will always be the same for that seed.

The sequence isn't stored in memory; it's generated from the seed using a mathematical formula.  Regular users don't need to know the details of the formula.  The formula was created to have many of the same mathematical properties as a truly random formula, even though it isn't truly random itself.

Usually, the seed is chosen based on the system time.  Suppose that the game uses the number of seconds in the day so far.  Since there are 86400 seconds in a day, there are 86400 possible sequences.  Since it is unlikely two players will start the game at exactly the same second, they will almost certainly experience two different sequences.

 

Offline TopAce

  • Stalwart contributor
  • 212
  • FREDder, FSWiki editor, and tester
Re: What's a "seed" in "rand"?
Thanks for all the answers. :yes: You've been helpful.
My community contributions - Get my campaigns from here.

I already announced my retirement twice, yet here I am. If I bring up that topic again, don't believe a word.