alpar@1: /* glprng02.c */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #include "glpenv.h" alpar@1: #include "glprng.h" alpar@1: #define xfault xerror alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * rng_unif_01 - obtain pseudo-random number in the range [0, 1] alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glprng.h" alpar@1: * double rng_unif_01(RNG *rand); alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * The routine rng_unif_01 returns a next pseudo-random number which is alpar@1: * uniformly distributed in the range [0, 1]. */ alpar@1: alpar@1: double rng_unif_01(RNG *rand) alpar@1: { double x; alpar@1: x = (double)rng_next_rand(rand) / 2147483647.0; alpar@1: xassert(0.0 <= x && x <= 1.0); alpar@1: return x; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * rng_uniform - obtain pseudo-random number in the range [a, b] alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glprng.h" alpar@1: * double rng_uniform(RNG *rand, double a, double b); alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * The routine rng_uniform returns a next pseudo-random number which is alpar@1: * uniformly distributed in the range [a, b]. */ alpar@1: alpar@1: double rng_uniform(RNG *rand, double a, double b) alpar@1: { double x; alpar@1: if (a >= b) alpar@1: xfault("rng_uniform: a = %g, b = %g; invalid range\n", a, b); alpar@1: x = rng_unif_01(rand); alpar@1: x = a * (1.0 - x) + b * x; alpar@1: xassert(a <= x && x <= b); alpar@1: return x; alpar@1: } alpar@1: alpar@1: /* eof */