Why can't I find the random() function in cppreference but can in Linux man page?

Viewed 57
2 Answers

Why can't I find the random() function in cppreference but can in Linux man page?

why there is no this random function in cppreference?

Because cppreference documents the C standard and not extensions and random() is a linux (BSD, then POSIX) extension to C standard.

Be sure to read future_test_macros(7) and standards(7). Note the random(3) parts:

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

   random(), srandom(), initstate(), setstate():
       _XOPEN_SOURCE >= 500
           || /* Glibc since 2.19: */ _DEFAULT_SOURCE
           || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE

and:

CONFORMING TO

       POSIX.1-2001, POSIX.1-2008, 4.3BSD.

randomize() and random() are not part of the standard C library. The function random() and srandom() are part of POSIX and not available on Windows. rand() and srand() are part of the standard C library and will be provided by any standard-conforming implementation of C.

This is the cause because you can't find the page of cppreference for random() function. It is a POSIX only function.

Related