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
- Copyright 2003, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- Copyright 2004, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms