Created
September 22, 2015 22:35
-
-
Save mesbahamin/ada14d271ccef582eb6c to your computer and use it in GitHub Desktop.
Confused about why this RNG doesn't ever generate a random first number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When this program is executed multiple times, the first number generated is always the same. | |
// The other numbers in the 5 number sequence are random. | |
// I'm confused about why the first number isn't random | |
#include <iostream> | |
#include <random> | |
#include <time.h> | |
using namespace std; | |
int main() | |
{ | |
const int upper_bound = 100; | |
const int lower_bound = 1; | |
default_random_engine e(time(0)); | |
uniform_int_distribution<int> u(lower_bound, upper_bound); | |
for (int counter = 1; counter <= 5; counter++) | |
{ | |
int secret = u(e); | |
cout << secret << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answered in this stack overflow question