1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

/**
 * This program will only run under Unixlike system. ~Bommel.
 **/

#define RANDOM_DEVICE "/dev/random" 
#define SLOTS         16
#define ABS(a)        (((a) < 0) ? -(a) : (a))


/* Playernames */
const char *playernames[SLOTS] =
{
     "Vinc [prophets]",
     "-maniac|Su- [prophets]",
     "Lucy [NK]",
     "Mara [NK]",
     "Slatte [PB]",
     "Painkiller [PK]",
     "UniT_4S6",
     "Phil [PK]",
     "qbit",
     "frozen soul [AxG]",
     "Mo [NK] // magoa",
     "totenkopf|pb",
     "Radiohe4d [eXiLe]",
     "[dtg] Nesquick",
     "Venom",
     "Alexyk"
};

/* Here the random numbers are stored */
int randarr[SLOTS];

/* Check if the given number is already in the list */
static int twice(int numb, int index)
{
    int y = 0;
    for(; y < SLOTS; y++)
        if(randarr[y] == numb && index != y)
            return 1;

    return 0;
}

/* Fill randarr with -1s */
static void fillrandarr(void)
{
    int y = 0;
    for(; y < SLOTS; y++)
        randarr[y] = -1;
}

int main(void)
{
    FILE *pF;
    pF = fopen(RANDOM_DEVICE,"r");

    if(pF)
    {
        int i = 0;
        int ind;

        fillrandarr();

        for(; i < SLOTS; i++)
        {
            do
            {
                /* Read random number as long theres one we dont have yet. */
                fread(&ind, sizeof(int), 1, pF);
                randarr[i] =  ABS(ind % SLOTS);
            }
            while(twice(randarr[i],i) );
        }
        fclose(pF);

        /* Announce: */
        printf("\n----- STARTPOSITIONS -----\n");

        ind = 0;
        for(i = 0; i < SLOTS; i = i+2)
            printf("#%.2d: %s vs. %s\n", ++ind,
                                         playernames[randarr[i]],
                                         playernames[randarr[i+1]]);

        return EXIT_SUCCESS;
    }
    else
    {
        /* We failed? Print why. */
        fprintf(stderr,"Failed to open Random device:\n");
        fprintf(stderr,"EC[%d]: %s\n",errno, strerror(errno));
        return EXIT_SUCCESS;
    }
}