random.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* classes: h_files */
  2. #ifndef RANDOMH
  3. #define RANDOMH
  4. /* Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice. */
  44. #include "libguile/__scm.h"
  45. /*
  46. * A plugin interface for RNGs
  47. *
  48. * Using this interface, it is possible for the application to tell
  49. * libguile to use a different RNG. This is desirable if it is
  50. * necessary to use the same RNG everywhere in the application in
  51. * order to prevent interference, if the application uses RNG
  52. * hardware, or if the application has special demands on the RNG.
  53. *
  54. * Look how the default generator is "plugged in" in scm_init_random().
  55. */
  56. typedef struct scm_rstate {
  57. int reserved0;
  58. double reserved1;
  59. /* Custom fields follow here */
  60. } scm_rstate;
  61. typedef struct scm_rng {
  62. size_t rstate_size; /* size of random state */
  63. unsigned long (*random_bits) (scm_rstate *state); /* gives 32 random bits */
  64. void (*init_rstate) (scm_rstate *state, char *seed, int n);
  65. scm_rstate *(*copy_rstate) (scm_rstate *state);
  66. } scm_rng;
  67. extern scm_rng scm_the_rng;
  68. /*
  69. * Default RNG
  70. */
  71. typedef struct scm_i_rstate {
  72. scm_rstate rstate;
  73. unsigned long w;
  74. unsigned long c;
  75. } scm_i_rstate;
  76. extern unsigned long scm_i_uniform32 (scm_i_rstate *);
  77. extern void scm_i_init_rstate (scm_i_rstate *, char *seed, int n);
  78. extern scm_i_rstate *scm_i_copy_rstate (scm_i_rstate *);
  79. /*
  80. * Random number library functions
  81. */
  82. extern scm_rstate *scm_c_make_rstate (char *, int);
  83. extern scm_rstate *scm_c_default_rstate (void);
  84. #define scm_c_uniform32(RSTATE) scm_the_rng.random_bits (RSTATE)
  85. extern double scm_c_uniform01 (scm_rstate *);
  86. extern double scm_c_normal01 (scm_rstate *);
  87. extern double scm_c_exp1 (scm_rstate *);
  88. extern unsigned long scm_c_random (scm_rstate *, unsigned long m);
  89. extern SCM scm_c_random_bignum (scm_rstate *, SCM m);
  90. /*
  91. * Scheme level interface
  92. */
  93. extern long scm_tc16_rstate;
  94. #define SCM_RSTATE(obj) ((scm_rstate *) SCM_CELL_WORD_1 (obj))
  95. #define SCM_RSTATEP(obj) (SCM_NIMP(obj) && (SCM_TYP16 (obj) == scm_tc16_rstate))
  96. extern unsigned char scm_masktab[256];
  97. extern SCM scm_var_random_state;
  98. extern SCM scm_random (SCM n, SCM state);
  99. extern SCM scm_copy_random_state (SCM state);
  100. extern SCM scm_seed_to_random_state (SCM seed);
  101. extern SCM scm_random_uniform (SCM state);
  102. extern SCM scm_random_solid_sphere_x (SCM v, SCM state);
  103. extern SCM scm_random_hollow_sphere_x (SCM v, SCM state);
  104. extern SCM scm_random_normal (SCM state);
  105. extern SCM scm_random_normal_vector_x (SCM v, SCM state);
  106. extern SCM scm_random_exp (SCM state);
  107. extern void scm_init_random (void);
  108. #endif /* RANDOMH */
  109. /*
  110. Local Variables:
  111. c-file-style: "gnu"
  112. End:
  113. */