0

I expect to receive different outputs, but I am getting two zeros independent of the seed value (here used 1 nad 2):

#include <iostream>
#include <string>
#include <random>

using namespace std;

int main()
{
  default_random_engine e1(1);
  default_random_engine e2(2);

  uniform_int_distribution<int> chose(0, 50);

  int a1 = chose(e1); cout << a1 << endl;
  int a2 = chose(e2); cout << a2 << endl;
}

What is wrong with my code?

Update: Based on the suggestions from @arekolek I did a little experiment. For seeds <= 2903 the first number is always the smallest number of the distribution. For seeds >= 2904 is smallest number +1. Increasing the seed this pattern remains.

robert
  • 3,539
  • 3
  • 35
  • 56
  • Only the first result happened to be the same in your case http://ideone.com/YPN4xD Also, it's not true that you get a zero independent of the seed value, try 21894 for example. – arekolek Feb 09 '16 at 11:01
  • The default engine is determined by the compiler, not ISO. You may want to state which compiler you're using. – MSalters Feb 09 '16 at 11:39
  • @MSalters g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010. Do not know what compiler the site cpp.sh uses, but I get the same result. – robert Feb 09 '16 at 11:42
  • I think this answers your question http://stackoverflow.com/a/32731387/1916449 – arekolek Feb 09 '16 at 11:56

0 Answers0