|
#include "SearchNAux.h"
#include <stdlib.h>
#include <assert.h>
unsigned long SearchItem::sm_cmpCount = 0;
//RandInRange() returns a random integer in the range [rMin, rMax].
//Precondition: RandInRange uses the standard rand() function inside,
//which returns an integer in the range [0, RAND_MAX]. Hence, the range
//width (rMax-rMin+1) should be in the range [0, RAND_MAX+1].
//If (rMax-rMin) > RAND_MAX, RandInRange will return an integer in the
//range [rMin, rMin+RAND_MAX] instead of [rMin, rMax]
//Note: RandInRange() has better random behavior when (rMax-rMin) < RAND_MAX/2
int RandInRange(int rMin, int rMax)
{
int r = 0;
assert( rMax > rMin );
assert( (rMax - rMin) <= RAND_MAX );
if (rMax > rMin)
{
int range = rMax - rMin + 1;
r = rand() % range + rMin;
}
return r;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I live in Greece with my wife and our two daughters. I am a professional software developer since 1999, using mostly C/C++ in my work.
My main expertise are: C/C++, STL, software optimization, generic programming and debugging. I am also very experienced in client–server programming, communications, concurrent programming, software security and cryptography. Finally, in my early professional years, I have worked a lot on cross-platform programming (Mac+Win).
I am familiar with the MFC, wxWidgets and Cplat GUI frameworks and the Python, Java, Pascal, Fortran, Prolog and Rexx programming languages.