int qanselExecuteBytecode(unsigned char* buff, int sizeofbuff, QAnselContext* ctx)
{
if (!qanselContextValidate(ctx)) return 0;
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- float seed = (float)((unsigned long)ts.tv_sec * 1000000000LL + ts.tv_nsec);
- qansel_rand_s(seed);
+ qansel_rand_s(qansel_hardware_getseed());
if (ctx != NULL && ctx->hidden_variable != 0)
{
#ifndef __BYTECODE_H__
#define __BYTECODE_H__
-#include <time.h>
#include "complex.h"
#include "context.h"
#include "display.h"
#endif
}
+
+float qansel_hardware_getseed()
+{
+ #ifdef CLOCK_MONOTONIC
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ float seed = (float)((unsigned long)ts.tv_sec * 1000000000LL + ts.tv_nsec);
+ #else
+ FILE* f = popen("date +%s", "r");
+ int c;
+ int tsl = 0;
+ char ts[128];
+
+ while ( (c = fgetc(f)) != EOF )
+ {
+ ts[tsl++] = c;
+ }
+ ts[tsl++] = 0;
+ fclose(f);
+ float seed = atof(ts);
+ #endif
+}
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
+#include <time.h>
#include <stddef.h>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include <sys/sysctl.h>
#endif
+
int qansel___get_core_count();
int qansel_get_core_count();
unsigned long int qansel_get_time();
int qansel_hardware_rand_supported();
unsigned char qansel_hardware_rand();
+float qansel_hardware_getseed();
#endif