Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

rand() warmup

Name: Anonymous 2012-01-20 16:28

void init_random() {
    clock_t start = clock();
    int i = 0;
    while (clock() - start == 0) {
        i++;
    }
    srand(time(0) + i);
}


17±3 ms
Is it okay?

Name: Anonymous 2012-01-20 16:37

Why not just do something like this:

#include <stdlib.h>
#include <sys/timeb.h>
void init_random(void)
{
    struct timeb tp;
    ftime(&tp);
    srand(tp.time<<sizeof(short)*8 | tp.millitm);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List