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:
@@ -50,7 +50,7 @@ static const DeviceButton g_keys[] =
|
||||
|
||||
static DeviceButton GetRandomKeyboardKey()
|
||||
{
|
||||
int index = rand()%ARRAYSIZE(g_keys);
|
||||
int index = RandomInt( ARRAYSIZE(g_keys) );
|
||||
return g_keys[index];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user