Don't use rand()%n. The function specified by the ANSI committee is a terrible linear congruential generator. In fact, it's so bad that the low order bit alternates. The algorithm implemented as RandomFloat() seems to be Park and Miller's "minimum standard" generator which is better (but not great). [See Knuth for more information.]
Any place where you would use rand()%n, use RandomInt(0, n) instead.
This commit is contained in:
@@ -92,7 +92,7 @@ int RandomSample::GetNextToPlay()
|
||||
int iIndexToPlay = 0;
|
||||
for( int i=0; i<5; i++ )
|
||||
{
|
||||
iIndexToPlay = rand() % m_pSamples.size();
|
||||
iIndexToPlay = RandomInt( m_pSamples.size() );
|
||||
if( iIndexToPlay != m_iIndexLastPlayed )
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user