Don't hack around low RAND_MAX values when RAND_MAX is high.
This was SVN commit r3469.
This commit is contained in:
parent
13897010d5
commit
67f8087b6f
@ -515,10 +515,26 @@ 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
|
||||
|
||||
// Silly heuristic: glibc has RAND_MAX of 2^31 - 1 while MS CRT has 2^15-1 or something...
|
||||
#if RAND_MAX < 65536
|
||||
static const uint XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1;
|
||||
|
||||
uint fullrand()
|
||||
{
|
||||
return rand()*(RAND_MAX+1) + rand();
|
||||
}
|
||||
#else
|
||||
static const uint XRAND_MAX = RAND_MAX;
|
||||
|
||||
uint fullrand()
|
||||
{
|
||||
return rand();
|
||||
}
|
||||
#endif
|
||||
|
||||
uint rand(uint min, uint max)
|
||||
{
|
||||
const uint XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1;
|
||||
|
||||
const uint range = (max-min);
|
||||
// huge interval or min > max
|
||||
if(range > XRAND_MAX)
|
||||
@ -532,7 +548,7 @@ uint rand(uint min, uint max)
|
||||
// generate random number in [0, range)
|
||||
uint x;
|
||||
do
|
||||
x = rand()*(RAND_MAX+1) + rand();
|
||||
x = fullrand();
|
||||
while(x >= range * inv_range);
|
||||
x /= inv_range;
|
||||
|
||||
|
@ -392,10 +392,12 @@ LibError debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file,
|
||||
h = strrchr (ctx.filename, '/');
|
||||
if (h != NULL)
|
||||
ctx.filename = h + 1;
|
||||
}
|
||||
|
||||
strncpy(file, ctx.filename, DBG_FILE_LEN);
|
||||
file[DBG_FILE_LEN]=0;
|
||||
strncpy(file, ctx.filename, DBG_FILE_LEN);
|
||||
file[DBG_FILE_LEN]=0;
|
||||
}
|
||||
else
|
||||
strcpy(file, "none");
|
||||
}
|
||||
|
||||
if (line)
|
||||
|
Loading…
Reference in New Issue
Block a user