/ Published in: C
Expand |
Embed | Plain Text
#include "stdlib.h" #include "stdint.h" uint64_t rand64() { // Combin 4 parts of low 16-bit of each rand() uint64_t R0 = (uint64_t)random() << 48; uint64_t R1 = (uint64_t)random() << 48 >> 16; uint64_t R2 = (uint64_t)random() << 48 >> 32; uint64_t R3 = (uint64_t)random() << 48 >> 48; return R0 | R1 | R2 | R3; } #define SEGS 100 #define TIMES 50000 // Show segments int main (int argc, char const *argv[]) { const uint64_t SEG = UINT64_MAX / SEGS; int f[SEGS] = { 0 }; for(int i = 0; i < TIMES; ++i) { uint64_t r = rand64(); f[r / SEG]++; } for (int i = 0; i < SEGS; ++i) { } return 0; }
You need to login to post a comment.
