urandom.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:58:06 +0100
changeset 14 862d63715611
parent 9 c3fecc82ade6
child 20 5fec678f931b
permissions -rw-r--r--
the long vector needs a typedef committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/tree.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int compare (unsigned char *a, unsigned char *b)
{
    if (*a > *b)
        return 1;
    return -1;
}

int main (int argc, char **argv)
{
    int i;
    int elements;
    int fd;
    unsigned char numbers[256] = { 0 };

    fd = open ("/dev/urandom", O_RDONLY);
    if (fd == -1)
        return EXIT_FAILURE;

    elements = read (fd, numbers, 255);
    numbers[elements] = 0;

    qsort (numbers, elements, sizeof (unsigned char), (void *)&compare);

    for (i = 0; i < elements; i++) {
        printf ("Number: %d\n", numbers[i]);
    }

    close (fd);

    return EXIT_SUCCESS;
}