mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(trunk libT) add some extra tests to tr_cryptoWeakRandInt()
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user