r/computerscience • • Oct 25 '26

Discussion Is simulation a function?

Question to settle a debate which I recently had with two of my colleagues.

One of my colleages argued all simulations are mathematically functions by definitions, since for every set of arguments they need to return one outcome. As an example we took a cellular automaton simulating a forest fire. They stated that everytime you give it a particular starting state, the end state will be the same, but I don't agree with that. To simulate humidity or different wind speeds and directions one might use an rng, so the same start map run twice might give 2 different results, which means it's mathematically not a function. My friend countered that because of how rngs work, with the same seed the will always be the same. You don't need to set a seed tho and I can imagine cases when it's even by design - for example when you can't be sure which direction the wind will be coming from and you want your simulation to account for any of them.

But here's the bit that we couldn't agree upon. My friend said, that even without seed, or using quantum randomness, that randomness is always based on something and as such must be treated as kind of a baked in argument. Because of that, if you manage to somehow recreate the exact same "randomness state", the outcome will never change.

From my point of view that's not the case. Even using simple time based pseudorandom number generators, to you as someone analysing such simulation, that rng should not be treated as argument. The way I see it it's just a black box, that "magically" gives you a number, you should treat it as truly random and use it to approximate all the different variables, that are too complicated to calculate each and every time you run the simulation or are just out of scope. Therefore the same input can give you different outputs, which makes the simulation itself not a function by mathematical definition.

What are your opinions on this?

0 Upvotes

41 comments sorted by

View all comments

Show parent comment

1

u/BudgetEye7539 Oct 26 '26

And what is about PRNG that don't have a state and that can be explicitly formulated as a pure function, just as sine or cosine? You give them the index of the sequence member, some parameter and they will return a pseudorandom number. Moreover, the most widespread PRNGs are made this way.

1

u/paperic Oct 26 '26

Then that index you're passing into the PRNG has to depend on some parameter to your function.

Or, alternatively, the function has to use a constant index, which makes the random number a constant.

Otherwise your function is not a pure function in the mathematical sense.

1

u/BudgetEye7539 Oct 26 '26

It also can just use a second argument, the seed or the key. Counter-based PRNG work this way.

1

u/paperic Oct 26 '26

Yes, but where do you get that argument from?

If you let the caller pick any argument as the PRNG seed, then the simulation can be a function.

But and if you're using a PRNG that's been already seeded, you can consider the seed of the function to be a silent argument to your function.

I'm not actually sure what you're trying to say.

1

u/BudgetEye7539 Oct 26 '26

This argument can be passed to the simulation as the "sequence ID" or seed. And the simulation can call the stateless PRNG using this seed as the second argument.

1

u/paperic Oct 26 '26

Yes, of course. But what are you trying to say?

In either case, the state of the PRNG has to be either a silent or an explicit argument of the simulation function, otherwise it's not a pure function.