Skip to content

Instantly share code, notes, and snippets.

@Andersama
Last active August 18, 2025 00:43
Show Gist options
  • Select an option

  • Save Andersama/4d3bc3a5f79189ddda6dbbf72095ab38 to your computer and use it in GitHub Desktop.

Select an option

Save Andersama/4d3bc3a5f79189ddda6dbbf72095ab38 to your computer and use it in GitHub Desktop.
//see: https://www.romu-random.org/romupaper.pdf
#include <cstdint>
struct romu192_random_t {
uint64_t xstate;
uint64_t ystate;
uint64_t zstate;
};
constexpr uint64_t romu64_random_r(romu192_random_t *rng) {
//#define ROMU_ROTL(d, lrot) ((d << (lrot)) | (d >> (8 * sizeof(d) - (lrot))))
uint64_t xp = rng->xstate;
uint64_t yp = rng->ystate;
uint64_t zp = rng->zstate;
rng->xstate = 15241094284759029579u * zp;
rng->ystate = yp - xp;
rng->ystate = ((rng->ystate << (12)) |
(rng->ystate >> (8 * sizeof(rng->ystate) - (12))));
rng->zstate = zp - yp;
rng->zstate = ((rng->zstate << (44)) |
(rng->zstate >> (8 * sizeof(rng->zstate) - (44))));
return xp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment