Linux, CentOS, Redhat G++ compiler and rand() / random function
Tuesday, November 18th, 2014If you are using the G++ compiler in Linux, CentOS, or Redhat there are a couple of steps to adding a random number generator to any project.
- Include the precompile library: #include <stdlib.h>
- Use the function and add seeding: first_number = rand()%6 +1);
The basic function in C++ for the G++ compiler in Linux looks like this:
#include <iostream>
#include <stdlib.h>
int main()
{
int first_number = rand()%6 +1;
std::cout << first_number;
return (0);
}