Home | Forums | What's new | Resources | |
slRandom really works? |
FacundoARG - Jun 4, 2010 |
Runik | Jun 4, 2010 | ||||||||
According to the SGL docs, slRandom() returns a FIXED type value ranging from 0.0 to 1.0 ... That might be the problem, as I'm not sure the modulo would work the way you want with a FIXED number |
cafe-alpha | Jun 5, 2010 | ||||||||||||||
I don't know about slRandom, but why not using the rand function instead ? In order to init the rand seed, as you can't use srand(time(NULL)); as it is usually done on PC, you may need the following crappy code before your program main loop:
Code:
(This code has been adapted from SGM_device_backup.c in Rockin'B Save Game Manager, which was taken from sgl sample 13-1). Then, in mixCards() function you can use the rand function:
Code:
It seems to work under yabause, however I didin't tested it on real hardware. I hope it will help your project. |
FacundoARG | Jun 5, 2010 | |||||
That is right, but If you call only one time slRandom() throws the same number even with FIXED numbers. I think we can't change the seed of generic numbers. Maybe if I get the time in seconds and then I call the function for example 59 times. This one is not a great solution but it's something. |
FacundoARG | Jun 5, 2010 | |||
Thanks cafe-alpha, I have already tested the rand() function also I have included the stdlib.h from the coff libraries. But I will test it again with the srand() patched. |
cafe-alpha | Jun 5, 2010 | |||||
Thank for your fast reply By the way, here is a sample project about the srand example : RandTest.zip.... In order to compile/test/etc, you need SaturnOrbit installed on your PC. Just launch the "GO.BAT" file in randTest directory. Typing `r' in the command prompt will recompile the project, and typing `t' will test the program under yabause. During the program execttion, hitting the Z key (mapped as keyboard's `D' under yabause) will call the rand function once. |
antime | Jun 5, 2010 | |||
slRandom stores its state in a system work area variable, maybe the idea is to manually set it to seed the RNG? |
FacundoARG | Jun 5, 2010 | |||||||||
Thanks friend, It works perfectly; now I need to test on a real Hardware. Your solution was to usefull
Yes I knew it, it is the (Randwork), but I don't know how can I call it. |
Amon | Jun 7, 2010 | |||
I use Mersenne twister random number generator, seeded with the system time if you are interested. |
antime | Jun 7, 2010 | |||||||||
Going by the memory map section in the end of the SGL reference doc, the system work area is always located at 0x60ffc00, and Randwork is located at offset 0xb0. You'd probably have to disassemble the RNG to figure out if the location stores just an integer or a fixed-point value.
Isn't one property of the Mersenne twister algorithm that every time it has exhausted its state table it will generate new state data, causing varying execution time? I've always been a bit suspicious of using it in a real-time environment like games where strong randomness isn't a very high priority (but I've also never actually profiled the algorithm to see if the variation is significant.) |