ObjectBase.cpp: replace incorrect RNG with rand(min,max)

lib: remove rand_up_to - superceded by rand(min,max)

This was SVN commit r3515.
This commit is contained in:
janwas 2006-02-15 04:03:29 +00:00
parent 5081b38c43
commit 9de2ec0c20
4 changed files with 6 additions and 20 deletions

View File

@ -279,9 +279,7 @@ void CObjectBase::CalculateVariation(std::set<CStr>& strings, variation_key& cho
// Choose a random number in the interval [0..totalFreq).
// (It shouldn't be necessary to use a network-synchronised RNG,
// since actors are meant to have purely visual manifestations.)
int randNum = (int)( ((float)rand() / RAND_MAX) * totalFreq );
debug_assert(randNum < totalFreq);
int randNum = rand(0, totalFreq);
// and use that to choose one of the variants
for (Iter it = matches.begin(); it != matches.end(); ++it)

View File

@ -382,17 +382,6 @@ u16 fp_to_u16(double in)
// return random integer in [0, limit).
// does not use poorly distributed lower bits of rand().
int rand_up_to(int limit)
{
// (i64 avoids overflowing in multiply)
const i64 ret = ((i64)limit * rand()) / (RAND_MAX+1);
debug_assert(0 <= ret && ret < limit);
return (int)ret;
}
// big endian!
void base32(const int len, const u8* in, u8* out)
{
@ -524,6 +513,8 @@ int match_wildcardw(const wchar_t* s, const wchar_t* w)
}
// return random integer in [min, max).
// avoids several common pitfalls; see discussion at
// http://www.azillionmonkeys.com/qed/random.html

View File

@ -303,9 +303,6 @@ inline bool feq(float f1, float f2)
extern u16 fp_to_u16(double in);
// return random integer in [0, limit).
// does not use poorly distributed lower bits of rand().
extern int rand_up_to(int limit);
// big endian!
extern void base32(const int len, const u8* in, u8* out);

View File

@ -842,9 +842,9 @@ static void* thread_func(void* arg)
{
void* user_data;
const int action = rand_up_to(4);
const uintptr_t key = rand_up_to(100);
const int sleep_duration_ms = rand_up_to(100);
const int action = rand(0, 4);
const uintptr_t key = rand(0, 100);
const int sleep_duration_ms = rand(0, 100);
debug_printf("thread %d: %s\n", thread_number, action_strings[action]);
//