author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:13 +0200 | |
changeset 63 | 5a82f89d607e |
parent 29 | 7abf6146898e |
child 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
20
5fec678f931b
getpass for windows does not work
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
2 |
* test/demos/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 |
} |