Log In  

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.

P#60123 2018-12-19 22:50 ( Edited 2018-12-19 22:51)

1

'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! :)

P#60150 2018-12-20 09:48

That does help. I still wonder how it applies to the game in the tutorial?

P#60223 2018-12-21 22:17

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.

P#60225 2018-12-21 23:06

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 10:05:04 | 0.006s | Q:16