Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math.random() is not random #17

Open
nguyengiabach1201 opened this issue Jul 15, 2024 · 1 comment
Open

math.random() is not random #17

nguyengiabach1201 opened this issue Jul 15, 2024 · 1 comment

Comments

@nguyengiabach1201
Copy link

math.random() in Lua will return pre-generated pseudo-random numbers. But in normal case, we can use math.randomseed(os.time()) as a walk-around. But we don't have os.time() function for GBA. Please help!

@evanbowman
Copy link
Owner

Hi! Unfortunately, the GBA does not have an operating system, which makes it difficult to provide much of the os library. Even professional quality GBA games did not have a reliable source of seed values for random number generation. Many GBA games would use tricks, like invoking the random number engine each frame while waiting for user input on the title screen, to introduce some additional unpredictability into the state of the random number sequence. I can try to give you some more suggestions for workarounds for seeding the RNG. But:

  1. The GBA does not have a system clock, unless there is a hardware clock built into the GBA cartridge that is running a game, so there is no reliable clock source value to return from os.time(). The makes it impossible to provide a good implementation of os.time()
  2. The GBA hardware always generally starts up in the same state. Therefore, there is no source of hardware randomness on the GBA that I can use to provide a seed value.

Please feel welcome to ask additional questions, or to propose new changes in the future. For this issue, other than suggesting possible workarounds, there is, regrettably, not much that I can do to provide a random seed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants