0

I gave a small racing game that randomnly generates it's course on start up. The course is too long to manually make and was wondering if there is a way I can generate the same randomn numbers every time? I don't want the course to be different everytime...

Would I have to save a list of randomn numbers in a plist?

Negora
  • 281
  • 4
  • 13

2 Answers2

2

You can use good old C-functions.

Set a seed for your RNG: srand(314). Get a random number: int randomNumber = rand();.

Not tested.. just form memory. Verify that it works. :)

bgfriend0
  • 1,152
  • 1
  • 14
  • 26
  • Ah ok. Wasn't sure if it would generate the same numbers every single time. Would I call srand again if I want to reset? My game is pretty simple and all runs in a single scene. – Negora Apr 10 '14 at 07:39
0

The thing to do is to pre generate your random courses. Create an assortment that you bundle with your app. Then you could just randomly select from the bundled courses.

uchuugaka
  • 12,679
  • 6
  • 37
  • 55