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:
Steve Checkoway
2006-06-26 12:14:30 +00:00
parent d2d24ceb4b
commit 80698277cf
19 changed files with 49 additions and 43 deletions
+2 -2
View File
@@ -1068,7 +1068,7 @@ static void SuperShuffleTaps( NoteData &inout, int iStartIndex, int iEndIndex )
set<int> vTriedTracks;
for( int i=0; i<4; i++ ) // probe max 4 times
{
int t2 = rand() % inout.GetNumTracks();
int t2 = RandomInt( inout.GetNumTracks() );
if( vTriedTracks.find(t2) != vTriedTracks.end() ) // already tried this track
continue; // skip
vTriedTracks.insert( t2 );
@@ -1941,7 +1941,7 @@ void NoteDataUtil::AddTapAttacks( NoteData &nd, Song* pSong )
TapNote::attack,
TapNote::SubType_invalid,
TapNote::original,
szAttacks[rand()%ARRAYSIZE(szAttacks)],
szAttacks[RandomInt(ARRAYSIZE(szAttacks))],
15.0f,
false,
0 );