summaryrefslogtreecommitdiff
path: root/noncore/games/zsame/dropin/kapplication.h
blob: f83d08e2f401aa8f860a9616a1122e0e21377785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>

static int _random() {
        static int init = false;
        if (!init) {
            unsigned int seed;
            init = true;
            int fd = ::open("/dev/urandom", O_RDONLY);
            if( fd<=0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed) ) {
                srand(getpid());
                seed = rand()+time(0);
            }
            if(fd>=0) close( fd );
            srand(seed);
        }
        return rand();
}