I can reproduce the problem on Mac OS X 10.9 with Xcode 5 - it looks like it might actually be a bug, or at least a limitation with rand()
/srand()
on OS X 10.9.
I recommend you use arc4random() instead, which works a lot better than rand()
, and which doesn't require that you randomize the seed:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
cout << (arc4random() % 14) << endl;
return 0;
}
Test:
$ g++ -Wall -O3 srand.cpp && ./a.out
5
$ ./a.out
8
$ ./a.out
0
$ ./a.out
8
$ ./a.out
11
$ ./a.out
8
$ ./a.out
3
$ ./a.out
13
$ ./a.out
9
$