From 7d32257fa2967fb81e87d8517d56d45d3acfafbc Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 13 Sep 2011 15:13:55 +1000 Subject: [PATCH] Add randomisation helper functions --- Makefile.am | 2 ++ random.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ random.hpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 random.cpp create mode 100644 random.hpp diff --git a/Makefile.am b/Makefile.am index 48eae25b..a9eadaf6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,7 @@ UTIL_INCLUDE = \ nocopy.hpp \ point.hpp \ pool.hpp \ + random.hpp \ range.hpp \ region.hpp \ signal.hpp \ @@ -51,6 +52,7 @@ UTIL_FILES = \ matrix.cpp \ point.cpp \ pool.cpp \ + random.cpp \ range.cpp \ region.cpp \ signal.cpp \ diff --git a/random.cpp b/random.cpp new file mode 100644 index 00000000..34b0acff --- /dev/null +++ b/random.cpp @@ -0,0 +1,42 @@ +/* + * This file is part of libgim. + * + * libgim 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 3 of the License, or (at your option) any later + * version. + * + * libgim 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 libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + + +#include "random.hpp" + +#include "range.hpp" + +using namespace util; + +namespace util { + template + T + random (void) + { return range::UNLIMITED.rand (); } + + template + T& + randomise (T &val) + { return val = util::random (); } +} + +template double util::random (void); +template float util::random (void); +template uint64_t util::random (void); + diff --git a/random.hpp b/random.hpp new file mode 100644 index 00000000..5bf64793 --- /dev/null +++ b/random.hpp @@ -0,0 +1,31 @@ +/* + * This file is part of libgim. + * + * libgim 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 3 of the License, or (at your option) any later + * version. + * + * libgim 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 libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + +#ifndef __UTIL_RANDOM_HPP +#define __UTIL_RANDOM_HPP + +namespace util { + template + T& randomise (T &); + + template + T random (void); +} + +#endif