I currently follow the tutorials of a guy called Benjamin Arnold, on YouTube:
C++/Game Tutorial 8: Random Number Generator! Time index: 7:38
The idea is to get familiar with random number generation in C++ for a lighter game project. Benjamin uses Microsoft Visual Studio, but I code along in Code::Blocks 16.01.
Every time I run this program, the first "random" number that gets generated is always 3, the rest are random. If I change the second argument for diceRoll to 10, the first number is always 5, so it seems the first number will always be the second argument divided by two. How come?
I follow Benjamin's coding examples exactly, and yet, his code works, and generates different first numbers!
#include <iostream>
#include <string>
#include <random>
#include <ctime>
using namespace std;
int main(){
default_random_engine randomGenerator(time(0));
uniform_int_distribution<int> diceRoll(1, 6);
cout << "I am rolling a " << diceRoll(randomGenerator) << endl;
cout << "I am rolling a " << diceRoll(randomGenerator) << endl;
cout << "I am rolling a " << diceRoll(randomGenerator) << endl;
cout << "I am rolling a " << diceRoll(randomGenerator) << endl;
return 0;
}
I have set my compiler to: Have g++ follow the C++11 ISO C++ language standard [-std=c++11] As dictated by Benjamin in the tutorial for the reason of being able to run the code that he uses.
Aucun commentaire:
Enregistrer un commentaire