C ++ rand () does not give the correct seed based number

I am working on assigning C ++ to my class, and we should use rand () with seed 99 to create a set of values. However, my problem is that when I try to create a value in our parameters, the number is different from what the instructor provided us for a specific first number. The code is shown below:

    int lottoNumber;
  srand (RANDOM_NUMBER_SEED);
  do
  {
    lottoNumber = rand ();
  } while (lottoNumber > 25 || lottoNumber < 1);

  cout << lottoNumber << endl;

The value obtained from this is 13, and the number to be produced is 2. Any help as to why this is different would be great, thanks!

+4
source share
3 answers

The algorithm used rand()is determined by the implementation.

, .

+9

. . , , , - .

, !!!

+4

rand() , cppreference.com std:: rand:

.

, - std:: mt19937

+3
source

Source: https://habr.com/ru/post/1669434/


All Articles