gsl_rng__transputer.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* rng/transputer.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl__config.h"
  20. #include <stdlib.h>
  21. #include "gsl_rng.h"
  22. /* This is the INMOS Transputer Development System generator. The sequence is,
  23. x_{n+1} = (a x_n) mod m
  24. with a = 1664525 and m = 2^32. The seed specifies the initial
  25. value, x_1.
  26. The theoretical value of x_{10001} is 1244127297.
  27. The period of this generator is 2^30. */
  28. static inline unsigned long int transputer_get (void *vstate);
  29. static double transputer_get_double (void *vstate);
  30. static void transputer_set (void *state, unsigned long int s);
  31. typedef struct
  32. {
  33. unsigned long int x;
  34. }
  35. transputer_state_t;
  36. static unsigned long int
  37. transputer_get (void *vstate)
  38. {
  39. transputer_state_t *state = (transputer_state_t *) vstate;
  40. state->x = (1664525 * state->x) & 0xffffffffUL;
  41. return state->x;
  42. }
  43. static double
  44. transputer_get_double (void *vstate)
  45. {
  46. return transputer_get (vstate) / 4294967296.0 ;
  47. }
  48. static void
  49. transputer_set (void *vstate, unsigned long int s)
  50. {
  51. transputer_state_t *state = (transputer_state_t *) vstate;
  52. if (s == 0)
  53. s = 1 ; /* default seed is 1. */
  54. state->x = s;
  55. return;
  56. }
  57. static const gsl_rng_type transputer_type =
  58. {"transputer", /* name */
  59. 0xffffffffUL, /* RAND_MAX */
  60. 1, /* RAND_MIN */
  61. sizeof (transputer_state_t),
  62. &transputer_set,
  63. &transputer_get,
  64. &transputer_get_double};
  65. const gsl_rng_type *gsl_rng_transputer = &transputer_type;