This just started happening recently. I noticed one of my programs wasn't giving random numbers, so I made a quick simple random number program to test it:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
srand(time(NULL))
std::cout << rand() << std::endl;
return 0;
}
Even when seeded, it keeps giving the same random number, just incremented a bit after each call. Here's a few of the numbers after running the program a few times: 874692194, 874709001, 874725808, 874742615, 874742615.
I put this program on one of my Linux machines just to be sure, and as expected, it produced random numbers correctly.
So why is my Mac not producing random numbers? I already tried restarting my computer, and the problem persisted.
Before anyone says "Why not use C++'s random library?", we aren't allowed to use C++11 features in this Computing class, so that's not a solution.
Aucun commentaire:
Enregistrer un commentaire