johannes-fetz / joengine

Jo Engine is an open source 2D and 3D game engine for the Sega Saturn written in C under MIT license
http://jo-engine.org/
MIT License
205 stars 32 forks source link

jo_random() Needs a Seed #16

Closed slinga-homebrew closed 4 years ago

slinga-homebrew commented 4 years ago

Thank you for developing Jo Engine. It has greatly simplified creating Saturn homebrew games.

I would like to request that jo_random() have the ability to take in a seed so that different random numbers are created. From what I have seen jo_random() returns the same numbers in the same order even after you restart the system. I am testing in Yabause.

Looking through the Jo Engine docs there does not appear to be a function to seed the random number generator. I would like to request the addition of "jo_srandom(int seed)" be added to the API. If the seed == 0, then jo_engine should use the Saturn's clock (or another method to generate a random number).

In "Twelve Snakes" I am using rand()\srand() and seeding it with the number of seconds. See https://github.com/slinga-homebrew/Twelve-Snakes/blob/master/main.c#L2018 for reference. I would prefer to use a Jo Engine function to do the equivalent.

Thank you again.

johannes-fetz commented 4 years ago

Hi,

Thanks for you suggestion :)

If you pull, you can now change the random seed like this:

jo_random_seed = 42;

By default the seed is based on the current date and time.

PS: I'll update the documentation tomorrow.

slinga-homebrew commented 4 years ago

Wow thank you!

johannes-fetz commented 4 years ago

You're wellcome :)