...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> #include <stdlib.h> void func(void) { enum { len = 12 }; void func(void) { /* * id will hold the ID, starting with the characters * "ID" followed by a random integer. */ char id[len]; int r; int num; /* ... */ r = rand(); /* Generate a random integer */ num = snprintf(id, len, "ID%-d", r); /* Generate the ID */ /* ... */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> #include <stdlib.h> #include <time.h> void func(void) { enum { len = 12 }; void func(void) { /* * id will hold the ID, starting with the characters * "ID" followed by a random integer. */ char id[len]; int r; int num; /* ... */ time_t now = time(NULL); if (now == (time_t)-1) { /* Handle error */ } srandom(now); /* Seed the PRNG with the current time */ /* ... */ r = random(); /* Generate a random integer */ num = snprintf(id, len, "ID%-d", r); /* Generate the ID */ /* ... */ } |
...