(trunk libT) add some extra tests to tr_cryptoWeakRandInt()
This commit is contained in:
parent
8f3660c334
commit
979eddf61d
|
@ -311,6 +311,8 @@ tr_cryptoRandInt( int upperBound )
|
|||
int noise;
|
||||
int val;
|
||||
|
||||
assert( upperBound > 0 );
|
||||
|
||||
if( RAND_pseudo_bytes ( (unsigned char *) &noise, sizeof noise ) >= 0 )
|
||||
{
|
||||
val = abs( noise ) % upperBound;
|
||||
|
@ -328,17 +330,22 @@ tr_cryptoRandInt( int upperBound )
|
|||
int
|
||||
tr_cryptoWeakRandInt( int upperBound )
|
||||
{
|
||||
static int init = 0;
|
||||
int val;
|
||||
static tr_bool init = FALSE;
|
||||
|
||||
assert( upperBound > 0 );
|
||||
|
||||
if( !init )
|
||||
{
|
||||
srand( tr_date( ) );
|
||||
init = 1;
|
||||
init = TRUE;
|
||||
}
|
||||
|
||||
return rand( ) % upperBound;
|
||||
|
||||
val = rand( ) % upperBound;
|
||||
assert( val >= 0 );
|
||||
assert( val < upperBound );
|
||||
return val;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue