initialize random seed; use high-order bits for better randomness

This commit is contained in:
Pierangelo Masarati 2006-08-25 15:15:13 +00:00
parent ca262ee8e6
commit c838ce513d
3 changed files with 24 additions and 8 deletions

View File

@ -288,7 +288,7 @@ do_base( char *uri, char *dn, struct berval *pass, char *base, char *filter, cha
int version = LDAP_VERSION3;
char *nullstr = "";
srand(pid);
srand( pid );
ldap_initialize( &ld, uri );
if ( ld == NULL ) {
@ -397,16 +397,19 @@ novals:;
/* Ok, got list of DNs, now start binding to each */
for ( i = 0; i < maxloop; i++ ) {
int j, k;
struct berval cred = { 0, NULL };
int j;
struct berval cred = { 0, NULL };
for ( j = 0, k = 0; k < ndns; k++) {
j = rand() % ndns;
}
#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
j = rand() % ndns;
#endif
j = ((double)ndns)*rand()/(RAND_MAX + 1.0);
if ( creds && !BER_BVISEMPTY( &creds[j] ) ) {
cred = creds[j];
}
if ( do_bind( uri, dns[j], &cred, 1, force, chaserefs, noinit, &ld )
&& !force )
{

View File

@ -215,6 +215,8 @@ do_random( char *uri, char *manager, struct berval *passwd,
char **values = NULL;
LDAPMessage *res = NULL, *e = NULL;
srand( pid );
attrs[ 0 ] = LDAP_NO_ATTRS;
attrs[ 1 ] = NULL;
@ -275,7 +277,12 @@ do_random( char *uri, char *manager, struct berval *passwd,
}
for ( i = 0; i < innerloop; i++ ) {
do_read( uri, manager, passwd, values[ rand() % nvalues ], &ld,
#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
int r = rand() % nvalues;
#endif
int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0);
do_read( uri, manager, passwd, values[ r ], &ld,
noattrs, 1, maxretries, delay, force,
chaserefs );
}

View File

@ -223,6 +223,8 @@ do_random( char *uri, char *manager, struct berval *passwd,
char **values = NULL;
LDAPMessage *res = NULL, *e = NULL;
srand( pid );
attrs[ 0 ] = attr;
attrs[ 1 ] = NULL;
@ -294,8 +296,12 @@ do_random( char *uri, char *manager, struct berval *passwd,
for ( i = 0; i < innerloop; i++ ) {
char buf[ BUFSIZ ];
#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
int r = rand() % nvalues;
#endif
int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0);
snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ rand() % nvalues ] );
snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ r ] );
do_search( uri, manager, passwd, sbase, buf, &ld, noattrs,
1, maxretries, delay, force, chaserefs );