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! :)
[Please log in to post a comment]