You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
575B

  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. // complimentary multiply with carry, pseudo random number generator
  5. // adapted from the public source code from wikipedia
  6. // https://en.wikipedia.org/wiki/Multiply-with-carry_pseudorandom_number_generator
  7. class cmwc {
  8. static const size_t CMWC_CYCLE = 4096; // as Marsaglia recommends
  9. static const size_t CMWC_C_MAX = 809430660; // as Marsaglia recommends
  10. uint32_t Q[CMWC_CYCLE];
  11. uint32_t c; // must be limited with CMWC_C_MAX
  12. unsigned i;
  13. public:
  14. void seed(unsigned int value);
  15. uint32_t next();
  16. };