mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
initialize random seed; use high-order bits for better randomness
This commit is contained in:
parent
ca262ee8e6
commit
c838ce513d
3 changed files with 24 additions and 8 deletions
|
|
@ -397,16 +397,19 @@ novals:;
|
|||
|
||||
/* Ok, got list of DNs, now start binding to each */
|
||||
for ( i = 0; i < maxloop; i++ ) {
|
||||
int j, k;
|
||||
int j;
|
||||
struct berval cred = { 0, NULL };
|
||||
|
||||
for ( j = 0, k = 0; k < ndns; k++) {
|
||||
|
||||
#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 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue