Reading SDL_srand seems to indicate that the same seed will reproduce the same pattern of output.
I imagine this behavior would work for sharing a specific level in rogue-like games, and/or multiplayer networked games.
So I’m curious, is the output repeatability itself cross-platform?
Here’s the test code:
#include <SDL3/SDL.h>
int main()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_srand(32);
for(int i = 0; i < 10; i ++)
{
SDL_Log("%d: %d", i, SDL_rand(100));
}
SDL_Quit();
}
I see.
The seed is a 64 bit unsigned number, and it is also the “state”. The state is multiplied by a constant value and 5 is added. Then the return value is that same state bit-shifted 32 bits so only the top 32 bits of the state are returned. Then range is applied (a nice little bit shift trick to avoid modulus).
Got it. I was expecting something more complex and possibly system-tied… but this gets the job done and should run pretty fast too. Perfect for simple game content, they do warn never to use it where security or money is involved.
Thank you.