SDL_rand_bits_r(3)

πŸ’– NAME πŸ’–

SDL_rand_bits_r β€” generate 32 pseudo-random bits. That's the whole gig bestie, she's a one-job icon ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_stdinc.h>

Uint32 SDL_rand_bits_r(Uint64 *state);

✨ DESCRIPTION ✨

Okay so real talk: you probably don't want this one. Like, you almost certainly want SDL_rand_r() to get an actual pseudo-random number instead. This is the low-level bit-shuffler, the one the cooler functions are built on. iykyk πŸ’…

And now the part where I have to be the responsible friend: there are no guarantees about the quality of the random sequence produced. None. Zero. Nada. So do not use this for security stuff (cryptography, passwords) and do not use it anywhere money is on the line (loot-boxes, casinos) 😭 β€” imagine losing the gacha because your RNG was vibes-based, absolutely not.

There are many random number libraries out there, each with different characteristics, and if you have serious needs you should go pick one of those. This one is for fun little non-serious randomness, periodt. πŸŽ€


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • state β€” a pointer to the current random number state. This may not be NULL. Not even a little. Not even for a second. πŸ™ˆ

πŸ’… RETURN VALUE πŸ’…

It hands you back a random value in the range of [0-SDL_MAX_UINT32]. Slay. 🫢


πŸ”₯ THREAD SAFETY πŸ”₯

This function is thread-safe β€” as long as the state pointer isn't being shared between threads. Share the state, share the chaos, and that's on you bestie πŸ’€


🌈 AVAILABILITY 🌈

This function has been available since SDL 3.2.0. So if you're on anything older, no bits for you πŸ¦‹


πŸ‘‘ SEE ALSO πŸ‘‘


Simple Directmedia Layer Β· SDL 3.4.18 β€” that's the source and the version, and this little love letter to SDL_rand_bits_r(3) is officially a wrap. go forth and randomize responsibly, bestie πŸŒΈπŸ’–πŸŽ€

πŸ“¦ where this page comes from