C++ Tutorial/Development/random
Generating random numbers
<source lang="cpp">#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;
}</source>