1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-12-12 09:50:29 +00:00

ngt_RandomStr(): : make it buildable with pre-ANSI C compilers

This commit is contained in:
Alexander Barton 2012-08-27 22:42:52 +02:00
parent 298cd9a327
commit 74be904018

View File

@ -135,24 +135,20 @@ ngt_TrimLastChr( char *String, const char Chr)
* Fill a String with random chars
*/
GLOBAL char *
ngt_RandomStr( char *String, const size_t len)
ngt_RandomStr(char *String, const size_t len)
{
static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`";
struct timeval t;
size_t i;
assert(String != NULL);
static const char chars[] =
"0123456789ABCDEFGHIJKLMNO"
"PQRSTUVWXYZabcdefghijklmn"
"opqrstuvwxyz!\"#$&'()*+,-"
"./:;<=>?@[\\]^_`";
struct timeval t;
gettimeofday(&t, NULL);
srand((unsigned)(t.tv_usec * t.tv_sec));
for (size_t i = 0; i < len; ++i) {
for (i = 0; i < len; ++i) {
String[i] = chars[rand() % (sizeof(chars) - 1)];
}
String[len] = '\0';
return String;