Changeset 6597


Ignore:
Timestamp:
Aug 20, 2008, 2:36:15 PM (13 years ago)
Author:
muks
Message:

Replace the random number generator inside peer-mgr with a
stupid faster one.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r6596 r6597  
    131131**/
    132132
     133/* The following is not a very high quality random number generator.  It
     134 * is mainly used as a simple stupid random number generator inside some
     135 * functions below. Please don't use it for anything else unless you
     136 * know what you're doing. Use tr_cryptoRandInt() instead.
     137 */
     138
     139static int
     140tr_simpleRandInt( int sup )
     141{
     142    static int init = 0;
     143    assert( sup > 0 );
     144
     145    if ( !init )
     146    {
     147        srand( tr_date() );
     148        init = 1;
     149    }
     150
     151    return rand() % sup;
     152}
     153
    133154static void
    134155managerLock( const struct tr_peerMgr * manager )
     
    601622            setme->priority = inf->pieces[piece].priority;
    602623            setme->peerCount = 0;
    603             setme->random = tr_cryptoRandInt( UINT16_MAX );
     624            setme->random = tr_simpleRandInt( UINT16_MAX );
    604625            setme->missingBlockCount = tr_cpMissingBlocksInPiece( tor->completion, piece );
    605626
     
    643664    if( retCount ) {
    644665        tr_peer ** tmp = tr_new( tr_peer*, retCount );
    645         i = tr_cryptoRandInt( retCount );
     666        i = tr_simpleRandInt( retCount );
    646667        memcpy( tmp, ret, sizeof(tr_peer*) * retCount );
    647668        memcpy( ret, tmp+i, sizeof(tr_peer*) * (retCount-i) );
     
    16311652        if(( n = tr_ptrArraySize( randPool )))
    16321653        {
    1633             c = tr_ptrArrayNth( randPool, tr_cryptoRandInt( n ));
     1654            c = tr_ptrArrayNth( randPool, tr_simpleRandInt( n ));
    16341655            c->doUnchoke = 1;
    16351656            t->optimistic = c->peer;
Note: See TracChangeset for help on using the changeset viewer.