Can't use arc4random(), even though I have #include <stdlib.h>

490 Views Asked by At

I'm trying to use arc4random_uniform() instead of rand % n in this program of mine, but I'm getting some problems related to my header files.

My code (summarized)

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <time.h>

int main(argc, char *argv[])
{
    //...
    int x = arc4random_uniform(n);
    //...
    return 0;
}

I'm getting the following error whenever I compile with GCC:

warning: implicit declaration of function 'arc4random_uniform' [-Wimplicit-function-declaration]
   70 |         int index = arc4random_uniform(option_amount);
      |                     ^~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe

In nearly every source that I find, the family arc4random functions all come from <stdlib.h>. Clearly, that header file is included. I tried reinstalling GCC via MSYS2, but that still didn't work. What could be going on here?

0

There are 0 best solutions below