Random problem (that is, problem with random())

Sergei Organov osv at topconrd.ru
Mon Mar 28 14:00:45 UTC 2005


Peter Dufault <dufault at hda.com> writes:

> I have some on-the-hardware simulation software that uses random(). As far as
> I can tell random() is defined in stdlib.h and present in the libiberty
> library in RTEMS, but when I try to compile the functions using random in
> either C++ or C code I get warnings.
> 
> As an example, for this function:
> 
> #include <stdlib.h>
> 
> extern void foo(void);
> extern void bar(long *l);
> 
> void foo(void) {
>      int l = random();
>      bar(&l);
> }
> 
> I get this for gcc:
> foo.c: In function ▒foo▓:
> foo.c:7: warning: implicit declaration of function ▒random▓

Here is a quote from GNU C library manual:

<quote>
   This section describes a set of random number generation functions
that are derived from BSD.  There is no advantage to using these
functions with the GNU C library; we support them for BSD compatibility
only.

   The prototypes for these functions are in `stdlib.h'.

 - Function: long int random (void)
</quote>

Thus, random() is BSD beast, not ISO or POSIX.

ISO C equivalent is called rand().

-- 
Sergei.




More information about the users mailing list