glprng.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* glprng.h (pseudo-random number generator) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #ifndef GLPRNG_H
  24. #define GLPRNG_H
  25. typedef struct RNG RNG;
  26. struct RNG
  27. { /* Knuth's portable pseudo-random number generator */
  28. int A[56];
  29. /* pseudo-random values */
  30. int *fptr;
  31. /* the next A value to be exported */
  32. };
  33. #define rng_create_rand _glp_rng_create_rand
  34. RNG *rng_create_rand(void);
  35. /* create pseudo-random number generator */
  36. #define rng_init_rand _glp_rng_init_rand
  37. void rng_init_rand(RNG *rand, int seed);
  38. /* initialize pseudo-random number generator */
  39. #define rng_next_rand _glp_rng_next_rand
  40. int rng_next_rand(RNG *rand);
  41. /* obtain pseudo-random integer in the range [0, 2^31-1] */
  42. #define rng_unif_rand _glp_rng_unif_rand
  43. int rng_unif_rand(RNG *rand, int m);
  44. /* obtain pseudo-random integer in the range [0, m-1] */
  45. #define rng_delete_rand _glp_rng_delete_rand
  46. void rng_delete_rand(RNG *rand);
  47. /* delete pseudo-random number generator */
  48. #define rng_unif_01 _glp_rng_unif_01
  49. double rng_unif_01(RNG *rand);
  50. /* obtain pseudo-random number in the range [0, 1] */
  51. #define rng_uniform _glp_rng_uniform
  52. double rng_uniform(RNG *rand, double a, double b);
  53. /* obtain pseudo-random number in the range [a, b] */
  54. #endif
  55. /* eof */