#include "THGeneral.h"
#include "THRandom.h"
-
-#ifndef _WIN32
-#include <fcntl.h>
-#include <unistd.h>
-#endif
+#include "ottery.h"
/* Code for the Mersenne Twister random generator.... */
#define n _MERSENNE_STATE_N
#define m _MERSENNE_STATE_M
/* Creates (unseeded) new generator*/
-static THGenerator* THGenerator_newUnseeded()
+static THGenerator* THGenerator_newUnseeded(void)
{
THGenerator *self = THAlloc(sizeof(THGenerator));
memset(self, 0, sizeof(THGenerator));
}
/* Creates new generator and makes sure it is seeded*/
-THGenerator* THGenerator_new()
+THGenerator* THGenerator_new(void)
{
THGenerator *self = THGenerator_newUnseeded();
THRandom_seed(self);
return 0;
}
-#ifndef _WIN32
-static unsigned long readURandomLong()
-{
- int randDev = open("/dev/urandom", O_RDONLY);
- unsigned long randValue;
- if (randDev < 0) {
- THError("Unable to open /dev/urandom");
- }
- ssize_t readBytes = read(randDev, &randValue, sizeof(randValue));
- if (readBytes < sizeof(randValue)) {
- THError("Unable to read from /dev/urandom");
- }
- close(randDev);
- return randValue;
-}
-#endif // _WIN32
-
unsigned long THRandom_seed(THGenerator *_generator)
{
-#ifdef _WIN32
- unsigned long s = (unsigned long)time(0);
-#else
- unsigned long s = readURandomLong();
-#endif
+ unsigned long s = ottery_rand_uint64();
THRandom_manualSeed(_generator, s);
return s;
}