From 10377a13d6a2b2cb88d5e7c5fc85539ef3171c01 Mon Sep 17 00:00:00 2001 From: green Date: Thu, 20 Jan 2000 01:49:41 +0000 Subject: I like base-36 better. --- usr.sbin/inetd/builtins.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/inetd/builtins.c b/usr.sbin/inetd/builtins.c index 2107b95..6ba404c 100644 --- a/usr.sbin/inetd/builtins.c +++ b/usr.sbin/inetd/builtins.c @@ -378,13 +378,27 @@ ident_stream(s, sep) /* Ident service (AKA "auth") */ case 'g': gflag = 1; random = 0; /* Shush, compiler. */ + /* + * The number of bits in "random" divided + * by the number of bits needed per iteration + * gives a more optimal way to reload the + * random number only when necessary. + * + * I'm using base-36, so I need at least 6 + * bits; round it up to 8 bits to make it + * easier. + */ for (i = 0; i < sizeof(garbage) - 1; i++) { - if (i % (sizeof(random) * 8 / 4) == 0) + const char *const base36 = + "0123456789" + "abcdefghijklmnopqrstuvwxyz"; + if (i % (sizeof(random) * 8 / 8) == 0) random = arc4random(); - snprintf(garbage + i, 2, "%.1x", - (int)random & 0xf); - random >>= 4; + garbage[i] = + base36[(random & 0xff) % 36]; + random >>= 8; } + garbage[i] = '\0'; break; case 'n': nflag = 1; -- cgit v1.1