Hi Mboffin, I have been working on your awesome game dev with PICO 8 pdf. In the lander tutorial, what does the srand(time()) at the end of step 5 do? I don’t see a difference if I inactivate it and just can’t seem to find the answer for it? Can you explain, please? Thank you for the fantastic guide.
'srand()' sets the seed for random numbers ( rnd() )
'time()' returns the ammount of seconds elapsed since you ran the cart
In computer science, no truly random number exists. They calculate a series of numbers based on something called a seed, which the programmer or program provides.
As you can see in the gif below, when the seed is 1, it always outputs the same "random" numbers, and the same is true with 2 or anything else.
So basically, srnd(time()) just generates a seed based on the elapsed seconds since you ran the cart.
Hope this helps! :)
That does help. I still wonder how it applies to the game in the tutorial?
The game uses rnd() to generate random terrain. If the PRNG (pseudo-random number generator) isn't seeded with some unpredictable number, it will always create the same layout.
[Please log in to post a comment]