I'm new to coding in C++ and I'm trying to get random numbers with the random library. This is my code:
#include <iostream>
#include <random>
int main() {
std::mt19937_64 gen{ std::random_device()() };
std::uniform_int_distribution<int> dist{0, 200};
int lineNumber = dist(gen);
std::cout << lineNumber;
}
I'm getting always number 69 using VSCode, but I've tried using an online compiler and the code above works properly, giving a different random number after each execution. How do I fix this in VSCode? Do I need to change something inside preferences? Or is there a problem with my compiler? Thanks in advance.
This might be helpful:
> g++ --version
g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> gdb --version
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Aucun commentaire:
Enregistrer un commentaire