Skip to content

Instantly share code, notes, and snippets.

@mesbahamin
Created September 22, 2015 22:35
Show Gist options
  • Save mesbahamin/ada14d271ccef582eb6c to your computer and use it in GitHub Desktop.
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.
// 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;
}
@mesbahamin
Copy link
Author

Answered in this stack overflow question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment