3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
29 /***********************************************************************
32 * rng_unif_01 - obtain pseudo-random number in the range [0, 1]
37 * double rng_unif_01(RNG *rand);
41 * The routine rng_unif_01 returns a next pseudo-random number which is
42 * uniformly distributed in the range [0, 1]. */
44 double rng_unif_01(RNG *rand)
46 x = (double)rng_next_rand(rand) / 2147483647.0;
47 xassert(0.0 <= x && x <= 1.0);
51 /***********************************************************************
54 * rng_uniform - obtain pseudo-random number in the range [a, b]
59 * double rng_uniform(RNG *rand, double a, double b);
63 * The routine rng_uniform returns a next pseudo-random number which is
64 * uniformly distributed in the range [a, b]. */
66 double rng_uniform(RNG *rand, double a, double b)
69 xfault("rng_uniform: a = %g, b = %g; invalid range\n", a, b);
70 x = rng_unif_01(rand);
71 x = a * (1.0 - x) + b * x;
72 xassert(a <= x && x <= b);