drand48_r(3)

✨ drand48_r(3) β€” the reentrant rand girlies πŸ’–

okay so bestie, welcome to drand48_r(3) from the Library Functions Manual 🌸 this is the whole family of reentrant pseudo-random number generators, and yes, they're all here, all nine of them, no cap. grab a snack πŸ“


🌈 NAME 🌈

drand48_r, erand48_r, lrand48_r, nrand48_r, mrand48_r, jrand48_r, srand48_r, seed48_r, lcong48_r β€” generate uniformly distributed pseudo-random numbers, but reentrantly πŸ’… (that's the whole serve, and it's iconic)


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc) β€” so cozy, so standard 🫢


πŸŽ€ SYNOPSIS πŸŽ€

First things first, you gotta invite the header:

#include <stdlib.h>

Now here's every single one of these babies, exactly as declared:

int drand48_r(struct drand48_data *restrict buffer,
              double *restrict result);
int erand48_r(unsigned short xsubi[3],
              struct drand48_data *restrict buffer,
              double *restrict result);

int lrand48_r(struct drand48_data *restrict buffer,
              long *restrict result);
int nrand48_r(unsigned short xsubi[3],
              struct drand48_data *restrict buffer,
              long *restrict result);

int mrand48_r(struct drand48_data *restrict buffer,
              long *restrict result);
int jrand48_r(unsigned short xsubi[3],
              struct drand48_data *restrict buffer,
              long *restrict result);

int srand48_r(long int seedval, struct drand48_data *buffer);
int seed48_r(unsigned short seed16v[3], struct drand48_data *buffer);
int lcong48_r(unsigned short param[7], struct drand48_data *buffer);

🧚 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

not me having to check the vibe check on macros πŸ™ˆ here's the deal for all functions shown above:

/* glibc >= 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE

πŸ’– DESCRIPTION πŸ’–

So these functions are the reentrant analogs of the ones described over in drand48(3) β€” same energy, but with boundaries. Instead of touching the global random generator state (which is, like, everyone's business πŸ’€), they use the data buffer you supply. your buffer, your rules, periodt ✨

Before the first use, this struct must be initialized. lowkey important. You can do it, for example, by filling it with zeros, or by calling one of srand48_r(), seed48_r(), or lcong48_r(). 🫢


πŸ¦‹ RETURN VALUE πŸ¦‹

The return value is 0. that's it. that's the whole tea. so chill. 😌


πŸ‘‘ ATTRIBUTES πŸ‘‘

For an explanation of the terms used in this section, see attributes(7). Here's the chart, reimagined as bullets because we don't do tables in this house πŸ’…

  • Interface: drand48_r(), erand48_r(), lrand48_r(), nrand48_r(), mrand48_r(), jrand48_r(), srand48_r(), seed48_r(), lcong48_r()
  • Attribute: Thread safety
  • Value: MT-Safe race:buffer
bestie, look at that race:buffer β€” the thread safety is conditional on your buffer. if multiple threads share the same buffer and you don't sync that, that's a race. MT-Safe, but with receipts. be careful 🫣

⭐ STANDARDS ⭐

GNU. that's the origin story, that's the lineage, slay 🌟


🌸 SEE ALSO 🌸


okay that's the whole page, you ate it, go forth and generate uniformly distributed pseudo-random numbers reentrantly like the main character you are πŸ‘‘βœ¨

Linux man-pages 6.20, dated 2026-02-08 β€” mwah, love that for us πŸ’œ bye bestie πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms