Archive for November 18th, 2014

Linux, CentOS, Redhat G++ compiler and rand() / random function

Tuesday, November 18th, 2014

If 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.

  1. Include the precompile library: #include <stdlib.h>
  2. 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);

}