diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index f646d7fb86..7f0069617b 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -15,13 +15,14 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdataset.c,v 1.65 2002/12/04 04:54:28 marka Exp $ */ +/* $Id: rdataset.c,v 1.66 2002/12/05 04:36:26 marka Exp $ */ #include #include #include +#include #include #include @@ -370,12 +371,10 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name, */ for (i = 0; i < count; i++) { dns_rdata_t rdata; -#ifndef HAVE_ARC4RANDOM - /* rand()'s lower bits are not random. */ - choice = i + (((u_int)rand()>>3) % (count - i)); -#else - choice = i + (u_int)arc4random() % (count - i); -#endif + isc_uint32_t val; + + isc_random_get(&val); + choice = i + (val % (count - i)); rdata = shuffled[i]; shuffled[i] = shuffled[choice]; shuffled[choice] = rdata; @@ -390,12 +389,11 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name, /* * "Cyclic" order. */ -#ifndef HAVE_ARC4RANDOM - /* rand()'s lower bits are not random. */ - unsigned int j = (((unsigned int)rand()) >> 3) % count; -#else - unsigned int j = (unsigned int)arc4random() % count; -#endif + isc_uint32_t val; + unsigned int j; + + isc_random_get(&val); + j = val % count; for (i = 0; i < count; i++) { if (order != NULL) sorted[j].key = (*order)(&shuffled[i], diff --git a/lib/isc/random.c b/lib/isc/random.c index c52b9a9957..9091cbf1c3 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: random.c,v 1.16 2002/12/04 01:19:28 marka Exp $ */ +/* $Id: random.c,v 1.17 2002/12/05 04:36:26 marka Exp $ */ #include @@ -64,7 +64,11 @@ isc_random_get(isc_uint32_t *val) initialize(); #ifndef HAVE_ARC4RANDOM - *val = rand(); + /* + * rand()'s lower bits are not random. + * rand()'s upper bit is zero. + */ + *val = ((rand() >> 4) & 0xffff) | ((rand() << 12) & 0xffff0000) ; #else *val = arc4random(); #endif