* misc/random.cc, misc/random.hh: New files.

* src/misc/Makefile.am (misc_HEADERS, libmisc_la_SOURCES): Add them.
This commit is contained in:
Alexandre Duret-Lutz 2004-11-12 16:27:39 +00:00
parent 67e133ae51
commit e54ddd46ed
4 changed files with 107 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2004-11-12 Alexandre Duret-Lutz <adl@src.lip6.fr>
* misc/random.cc, misc/random.hh: New files.
* src/misc/Makefile.am (misc_HEADERS, libmisc_la_SOURCES): Add them.
2004-11-10 Alexandre Duret-Lutz <adl@src.lip6.fr> 2004-11-10 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/evtgbaparse/public.hh (evtgba_parse): Fix doxygen comments. * src/evtgbaparse/public.hh (evtgba_parse): Fix doxygen comments.

View file

@ -33,6 +33,7 @@ misc_HEADERS = \
hash.hh \ hash.hh \
minato.hh \ minato.hh \
modgray.hh \ modgray.hh \
random.hh \
version.hh version.hh
noinst_LTLIBRARIES = libmisc.la noinst_LTLIBRARIES = libmisc.la
@ -43,4 +44,5 @@ libmisc_la_SOURCES = \
freelist.cc \ freelist.cc \
minato.cc \ minato.cc \
modgray.cc \ modgray.cc \
random.cc \
version.cc version.cc

54
src/misc/random.cc Normal file
View file

@ -0,0 +1,54 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include "random.hh"
#include <cstdlib>
namespace spot
{
void
srand(unsigned int seed)
{
::srand(seed);
}
double
drand()
{
double r = ::rand();
return r / (1.0 + RAND_MAX);
}
int
mrand(int max)
{
int res = static_cast<int>(max * drand());
return res;
}
int
rrand(int min, int max)
{
return min + static_cast<int>((max - min + 1) * drand());
}
}

46
src/misc/random.hh Normal file
View file

@ -0,0 +1,46 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
namespace spot
{
/// \brief Reset the seed of the pseudo-random number generator.
///
/// \see drand, mrand, rrand
void srand(unsigned int seed);
/// \brief Compute a pseudo-random integer value between \a min and
/// \a max included.
///
/// \see drand, mrand, srand
int rrand(int min, int max);
/// \brief Compute a pseudo-random integer value between 0 and
/// \a max-1 included.
///
/// \see drand, rrand, srand
int mrand(int max);
/// \brief Compute a pseudo-random double value
/// between 0.0 and 1.0 (1.0 excluded).
///
/// \see mrand, rrand, srand
double drand();
}