Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : rand_r

intrand_r(unsigned int * seed) ;

Return Type : int

Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
Read about return values of rand_r function .

1st Parameter Type : unsigned int *

A pointer to an unsigned integer, allowing indirect access to a variable that holds non-negative values (0 to 4,294,967,295 on most platforms). Commonly used for updating or referencing data without copying it.

1st Parameter

Pointer to an unsigned integer that stores the seed value for generating random numbers. The seed is updated with each call to ensure unique results.

Read more about parameters of rand_r in parameters section
The rand_rfunction in C language Generates a pseudo-random number using a given seed, thread-safe.
The rand_r function is a reentrant version of rand(). It uses the provided seed to generate a pseudo-random number, making it suitable for multi-threaded applications. Each call modifies the seed, which should be used in subsequent calls to maintain the random sequence. This function is thread-safe because it doesn't rely on global state.
The rand_rfunction takes 1 parameter:
  • unsigned int * `seed`: Pointer to an unsigned integer that stores the seed value for generating random numbers. The seed is updated with each call to ensure unique results.
Generates a pseudo-random number in the range [0, `RAND_MAX`] using the seed provided by `seed`. Unlike `rand`, this function is thread-safe as it does not use global state. The `seed` value is updated with each call, allowing for reproducible results.
The rand_r function return value :
  • Returns a pseudo-random integer between 0 and RAND_MAX, inclusive

Output

This example demonstrates basic usage of rand_r(). It initializes the seed with the current time and generates five random numbers.