randomize •rand, don't use m_i32 for time seconds

This commit is contained in:
dzaima 2021-09-04 23:26:35 +03:00
parent 4f88faa3d4
commit 7547fc1679
2 changed files with 11 additions and 7 deletions

View File

@ -422,7 +422,11 @@ B makeRand_c1(B t, B x) {
static B randNS; static B randNS;
B getRandNS() { B getRandNS() {
if (randNS.u == 0) { if (randNS.u == 0) {
randNS = c1(bi_makeRand,m_f64(RANDSEED)); #if RANDSEED==0
randNS = c1(bi_makeRand, m_f64(nsTime()));
#else
randNS = c1(bi_makeRand, m_f64(RANDSEED));
#endif
gc_add(randNS); gc_add(randNS);
} }
return inc(randNS); return inc(randNS);
@ -541,13 +545,13 @@ B list_c1(B d, B x) {
B unixTime_c1(B t, B x) { B unixTime_c1(B t, B x) {
dec(x); dec(x);
return m_i32(time(NULL)); return m_f64(time(NULL));
} }
B monoTime_c1(B t, B x) { B monoTime_c1(B t, B x) {
dec(x); dec(x);
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return m_i32(ts.tv_sec); return m_f64(ts.tv_sec + ts.tv_nsec/1e9);
} }
B delay_c1(B t, B x) { B delay_c1(B t, B x) {
f64 sf = o2f(x); f64 sf = o2f(x);

View File

@ -37,7 +37,7 @@
#define FORMATTER 1 // use self-hosted formatter for output #define FORMATTER 1 // use self-hosted formatter for output
#endif #endif
#ifndef RANDSEED #ifndef RANDSEED
#define RANDSEED 1 // random seed used to make •rand #define RANDSEED 0 // random seed used to make •rand (0 for using time)
#endif #endif
// #define HEAP_VERIFY // enable usage of heapVerify() // #define HEAP_VERIFY // enable usage of heapVerify()
@ -142,9 +142,9 @@ static const u16 EXT_TAG = 0b0111111111110100; // 7FF4 0111111111110100ddddddddd
static const u16 MD1_TAG = 0b1111111111110010; // FFF2 1111111111110010ppppppppppppppppppppppppppppppppppppppppppppp000 1-modifier static const u16 MD1_TAG = 0b1111111111110010; // FFF2 1111111111110010ppppppppppppppppppppppppppppppppppppppppppppp000 1-modifier
static const u16 MD2_TAG = 0b1111111111110011; // FFF3 1111111111110011ppppppppppppppppppppppppppppppppppppppppppppp000 2-modifier static const u16 MD2_TAG = 0b1111111111110011; // FFF3 1111111111110011ppppppppppppppppppppppppppppppppppppppppppppp000 2-modifier
static const u16 FUN_TAG = 0b1111111111110100; // FFF4 1111111111110100ppppppppppppppppppppppppppppppppppppppppppppp000 function static const u16 FUN_TAG = 0b1111111111110100; // FFF4 1111111111110100ppppppppppppppppppppppppppppppppppppppppppppp000 function
static const u16 NSP_TAG = 0b1111111111110101; // FFF5 1111111111110101ppppppppppppppppppppppppppppppppppppppppppppp000 namespace maybe? static const u16 NSP_TAG = 0b1111111111110101; // FFF5 1111111111110101ppppppppppppppppppppppppppppppppppppppppppppp000 namespace
static const u16 OBJ_TAG = 0b1111111111110110; // FFF6 1111111111110110ppppppppppppppppppppppppppppppppppppppppppppp000 custom object (e.g. bigints) static const u16 OBJ_TAG = 0b1111111111110110; // FFF6 1111111111110110ppppppppppppppppppppppppppppppppppppppppppppp000 custom/internal object
static const u16 ARR_TAG = 0b1111111111110111; // FFF7 1111111111110111ppppppppppppppppppppppppppppppppppppppppppppp000 array (everything else is an atom) static const u16 ARR_TAG = 0b1111111111110111; // FFF7 1111111111110111ppppppppppppppppppppppppppppppppppppppppppppp000 array (everything else here is an atom)
static const u16 VAL_TAG = 0b1111111111110 ; // FFF. 1111111111110................................................... pointer to Value, needs refcounting static const u16 VAL_TAG = 0b1111111111110 ; // FFF. 1111111111110................................................... pointer to Value, needs refcounting
#define ftag(X) ((u64)(X) << 48) #define ftag(X) ((u64)(X) << 48)
#define tag(V, T) b(((u64)(V)) | ftag(T)) #define tag(V, T) b(((u64)(V)) | ftag(T))