* configure.ac: Check for srand48 and drand48.
* src/misc/random.cc (srand, drand): Use srand48 and drand48 if available.
This commit is contained in:
parent
5bcb6091fd
commit
4a7486bbff
3 changed files with 15 additions and 3 deletions
|
|
@ -27,24 +27,30 @@ namespace spot
|
|||
void
|
||||
srand(unsigned int seed)
|
||||
{
|
||||
#if HAVE_SRAND48 && HAVE_DRAND48
|
||||
::srand48(seed);
|
||||
#else
|
||||
::srand(seed);
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
drand()
|
||||
{
|
||||
#if HAVE_SRAND48 && HAVE_DRAND48
|
||||
return ::drand48();
|
||||
#else
|
||||
double r = ::rand();
|
||||
return r / (1.0 + RAND_MAX);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
mrand(int max)
|
||||
{
|
||||
int res = static_cast<int>(max * drand());
|
||||
return res;
|
||||
return static_cast<int>(max * drand());
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
rrand(int min, int max)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue