Home > Software engineering >  Where is random.h in msys2
Where is random.h in msys2

Time:04-19

I am using MSYS2 mingw 64 when compiling code that needs the header random.h I am trying to make that code work on both Linux and windows with the least amount of changes

#include <sys/random.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>


int main()
{
    srand(time(NULL));


    return 0;
}

I ran this command pacman -S msys2-runtime-devel to download the random.h header file and it is located in sys official link

on linux, the file is included using #include <linux/random.c> but I don't know what to use on windows or if I have to do something completely different

When I comment the first line I get this warning

main.c:10:9: warning: implicit declaration of function 'srand' [-Wimplicit-function-declaration]
   10 |         srand(time(NULL));
      |         ^~~~~

CodePudding user response:

As per the linked documentation,

  • srand is declared in #include <stdlib.h>.

  • rand is declared in #include <stdlib.h>.

Neither requires including random.h or linux/random.c.

  • Related