Generating random numbers : random « Development « C++ Tutorial






#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

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

    int randomNumber = rand();

    int die = (randomNumber % 6) + 1;
    cout << "You rolled a " << die << endl;

    return 0;
}








5.31.random
5.31.1.Generating random numbers