Parent Directory
|
Revision Log
Update
| 1 | sysadm | 1.2 | #include <sys/time.h> |
| 2 | sysadm | 1.1 | #include <stdlib.h> |
| 3 | |||
| 4 | static int d2cs_random_init(void) | ||
| 5 | { | ||
| 6 | struct timeval tv; | ||
| 7 | |||
| 8 | if(!gettimeofday(&tv,NULL)) { | ||
| 9 | const unsigned int seed=(unsigned int)tv.tv_sec^tv.tv_usec; | ||
| 10 | srandom(seed); | ||
| 11 | return 0; | ||
| 12 | }else{ | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | |||
| 16 | } | ||
| 17 | |||
| 18 | extern int d2cs_random_num(void) | ||
| 19 | { | ||
| 20 | if(d2cs_random_init()) | ||
| 21 | return -1; | ||
| 22 | return (random()%10); | ||
| 23 | } | ||
| 24 | |||
| 25 | extern char d2cs_random_char(void) | ||
| 26 | { | ||
| 27 | if(d2cs_random_init()) | ||
| 28 | return -1; | ||
| 29 | return (random()%7+97); | ||
| 30 | } |
| webmaster@leafok.com | ViewVC Help |
| Powered by ViewVC 1.3.0-beta1 |