/usr/include/gromacs/gmx_random.h is in gromacs-dev 4.6.5-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | /*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2008, The GROMACS development team,
* check out http://www.gromacs.org for more information.
* Copyright (c) 2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* GROMACS 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GROMACS; if not, see
* http://www.gnu.org/licenses, or write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* If you want to redistribute modifications to GROMACS, please
* consider that scientific software is very special. Version
* control is crucial - bugs must be traceable. We will be happy to
* consider code for inclusion in the official distribution, but
* derived work must not be called official GROMACS. Details are found
* in the README & COPYING files - if they are missing, get the
* official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
#ifndef _GMX_RANDOM_H_
#define _GMX_RANDOM_H_
#include "visibility.h"
#include <stdio.h>
#include "types/simple.h"
#ifdef __cplusplus
extern "C" {
#endif
/*! \brief Abstract datatype for a random number generator
*
* This is a handle to the full state of a random number generator.
* You can not access anything inside the gmx_rng structure outside this
* file.
*/
typedef struct gmx_rng *
gmx_rng_t;
/*! \brief Returns the size of the RNG integer data structure
*
* Returns the size of the RNG integer data structure.
* \threadsafe Yes.
*/
GMX_LIBGMX_EXPORT
int
gmx_rng_n(void);
/*! \brief Create a new RNG, seeded from a single integer.
*
* If you dont want to pick a seed, just call it as
* rng=gmx_rng_init(gmx_rng_make_seed()) to seed it from
* the system time or a random device.
*
* \param seed Random seed, unsigned 32-bit integer.
*
* \return Reference to a random number generator, or NULL if there was an
* error.
*
* \threadsafe Yes.
*/
GMX_LIBGMX_EXPORT
gmx_rng_t
gmx_rng_init(unsigned int seed);
/*! \brief Generate a 'random' RNG seed.
*
* This routine tries to get a seed from /dev/random if present,
* and if not it uses time-of-day and process id to generate one.
*
* \return 32-bit unsigned integer random seed.
*
* Tip: If you use this in your code, it is a good idea to write the
* returned random seed to a logfile, so you can recreate the exact sequence
* of random number if you need to reproduce your run later for one reason
* or another.
*
* \threadsafe Yes.
*/
GMX_LIBGMX_EXPORT
unsigned int
gmx_rng_make_seed(void);
/*! \brief Initialize a RNG with 624 integers (>32 bits of entropy).
*
* The Mersenne twister RNG used in Gromacs has an extremely long period,
* but when you only initialize it with a 32-bit integer there are only
* 2^32 different possible sequences of number - much less than the generator
* is capable of.
*
* If you really need the full entropy, this routine makes it possible to
* initialize the RNG with up to 624 32-bit integers, which will give you
* up to 2^19968 bits of entropy.
*
* \param seed Array of unsigned integers to form a seed
* \param seed_length Number of integers in the array, up to 624 are used.
*
* \return Reference to a random number generator, or NULL if there was an
* error.
*
* \threadsafe Yes.
*/
gmx_rng_t
gmx_rng_init_array(unsigned int seed[],
int seed_length);
/*! \brief Release resources of a RNG
*
* This routine destroys a random number generator and releases all
* resources allocated by it.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*
* \threadsafe Function itself is threadsafe, but you should only destroy a
* certain RNG once (i.e. from one thread).
*/
GMX_LIBGMX_EXPORT
void
gmx_rng_destroy(gmx_rng_t rng);
/*! \brief Get the state of a RNG
*
* This routine stores the random state in mt and mti, mt should have
* a size of at least 624, mt of 1.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*/
GMX_LIBGMX_EXPORT
void
gmx_rng_get_state(gmx_rng_t rng, unsigned int *mt, int *mti);
/*! \brief Set the state of a RNG
*
* This routine sets the random state from mt and mti, mt should have
* a size of at least 624.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*/
GMX_LIBGMX_EXPORT
void
gmx_rng_set_state(gmx_rng_t rng, unsigned int *mt, int mti);
/*! \brief Random 32-bit integer from a uniform distribution
*
* This routine returns a random integer from the random number generator
* provided, and updates the state of that RNG.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*
* \return 32-bit unsigned integer from a uniform distribution.
*
* \threadsafe Function yes, input data no. You should not call this function
* from two different threads using the same RNG handle at the
* same time. For performance reasons we cannot lock the handle
* with a mutex every time we need a random number - that would
* slow the routine down a factor 2-5. There are two simple
* solutions: either use a mutex and lock it before calling
* the function, or use a separate RNG handle for each thread.
*/
GMX_LIBGMX_EXPORT
unsigned int
gmx_rng_uniform_uint32(gmx_rng_t rng);
/*! \brief Random gmx_real_t 0<=x<1 from a uniform distribution
*
* This routine returns a random floating-point number from the
* random number generator provided, and updates the state of that RNG.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*
* \return floating-point number 0<=x<1 from a uniform distribution.
*
* \threadsafe Function yes, input data no. You should not call this function
* from two different threads using the same RNG handle at the
* same time. For performance reasons we cannot lock the handle
* with a mutex every time we need a random number - that would
* slow the routine down a factor 2-5. There are two simple
* solutions: either use a mutex and lock it before calling
* the function, or use a separate RNG handle for each thread.
*/
GMX_LIBGMX_EXPORT
real
gmx_rng_uniform_real(gmx_rng_t rng);
/*! \brief Random gmx_real_t from a gaussian distribution
*
* This routine returns a random floating-point number from the
* random number generator provided, and updates the state of that RNG.
*
* The Box-Muller algorithm is used to provide gaussian random numbers. This
* is not the fastest known algorithm for gaussian numbers, but in contrast
* to the alternatives it is very well studied and you can trust the returned
* random numbers to have good properties and no correlations.
*
* \param rng Handle to random number generator previously returned by
* gmx_rng_init() or gmx_rng_init_array().
*
* \return Gaussian random floating-point number with average 0.0 and
* standard deviation 1.0. You can get any average/mean you want
* by first multiplying with the desired average and then adding
* the average you want.
*
* \threadsafe Function yes, input data no. You should not call this function
* from two different threads using the same RNG handle at the
* same time. For performance reasons we cannot lock the handle
* with a mutex every time we need a random number - that would
* slow the routine down a factor 2-5. There are two simple
* solutions: either use a mutex and lock it before calling
* the function, or use a separate RNG handle for each thread.
*
* It works perfectly to mix calls to get uniform and gaussian random numbers
* from the same generator, but since it will affect the sequence of returned
* numbers it is probably better to use separate random number generator
* structures.
*/
GMX_LIBGMX_EXPORT
real
gmx_rng_gaussian_real(gmx_rng_t rng);
/* Return a new gaussian random number with expectation value
* 0.0 and standard deviation 1.0. This routine uses a table
* lookup for maximum speed.
*
* WARNING: The lookup table is 16k by default, which means
* the granularity of the random numbers is coarser
* than what you get from gmx_rng_gauss_real().
* In most cases this is no problem whatsoever,
* and it is particularly true for BD/SD integration.
* Note that you will NEVER get any really extreme
* numbers: the maximum absolute value returned is
* 4.0255485.
*
* threadsafe: yes
*/
GMX_LIBGMX_EXPORT
real
gmx_rng_gaussian_table(gmx_rng_t rng);
#ifdef __cplusplus
}
#endif
#endif /* _GMX_RANDOM_H_ */
|