c++ - Why am I getting numbers outside the range I passed? -
i new c++ , not understand why numbers outside range. i
commented thought initial range
#include <vector> #include <iostream> #include <random> #include <time.h> using namespace std; using std::vector; int main() { vector<int> deck; default_random_engine eng(time(0));
i thought here specify range of random numbers instead numbers outside range
uniform_int_distribution<int> dis(0, 51); int pos1; int pos2; int num1; int num2; int i; int n; int m; (i = 1; < 53; i++) { deck.push_back(i); } pos1 = dis(eng); pos2 = dis(eng); num1 = deck.at(pos1); num2 = deck.at(pos2); (n = 0; n < 100; n++) { pos1 = dis(eng); pos2 = dis(eng); cout << pos1 << "\n" << pos2; } }
it looks problem in last line cout << pos1 << "\n" << pos2;
(here forgot add << "\n"
). if program prints 4 numbers (e.g. 22, 23, 24, 25) see following text:
22 2324 25
so number 2324 outside range, concatenation of 2 numbers.
Comments
Post a Comment