author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Tue, 19 May 2009 02:58:59 +0200 | |
changeset 93 | 66b3596f71b6 |
parent 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* urandom.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <fcntl.h> |
|
9 |
#include <unistd.h> |
|
10 |
||
11 |
int compare (unsigned char *a, unsigned char *b) |
|
12 |
{ |
|
13 |
if (*a > *b) |
|
14 |
return 1; |
|
15 |
return -1; |
|
16 |
} |
|
17 |
||
18 |
int main (int argc, char **argv) |
|
19 |
{ |
|
20 |
int i; |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
27
diff
changeset
|
21 |
int elements; |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
27
diff
changeset
|
22 |
int fd; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
20
diff
changeset
|
23 |
|
0 | 24 |
unsigned char numbers[256] = { 0 }; |
25 |
||
26 |
fd = open ("/dev/urandom", O_RDONLY); |
|
27 |
if (fd == -1) |
|
28 |
return EXIT_FAILURE; |
|
29 |
||
30 |
elements = read (fd, numbers, 255); |
|
31 |
numbers[elements] = 0; |
|
20
5fec678f931b
getpass for windows does not work
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
32 |
close (fd); |
0 | 33 |
|
34 |
qsort (numbers, elements, sizeof (unsigned char), (void *)&compare); |
|
35 |
||
36 |
for (i = 0; i < elements; i++) { |
|
37 |
printf ("Number: %d\n", numbers[i]); |
|
38 |
} |
|
39 |
||
40 |
return EXIT_SUCCESS; |
|
41 |
} |