Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try also this #17

Open
Zibri opened this issue Apr 6, 2019 · 3 comments
Open

try also this #17

Zibri opened this issue Apr 6, 2019 · 3 comments

Comments

@Zibri
Copy link

Zibri commented Apr 6, 2019

#ifndef ZIBRI128_H
#define ZIBRI128_H

/* Modified by D. Lemire, August 2017 */
#include "splitmix64.h"
#include <stdint.h>

// state for zibri128
uint64_t zibri128_s[2];


static inline uint64_t rotr(const uint64_t x, int k) {
  return (x >> k) | (x << (64 - k));
}


// call this one before calling zibri128
static inline void zibri128_seed(uint64_t seed) {
  zibri128_s[0] = splitmix64_stateless(seed);
  zibri128_s[1] = splitmix64_stateless(seed + 1);
}

// returns random number, modifies zibri128_s
static inline uint64_t zibri128(void) {
  const uint64_t s0 = zibri128_s[0];
  const uint64_t s1 = zibri128_s[1];
  const uint64_t result = rotr(s0 + s1,8);

  zibri128_s[0] = result;
  zibri128_s[1] = s0;                 

  return result;
}

#endif // ZIBRI128_H

is the fastest so far...

@Zibri
Copy link
Author

Zibri commented Apr 6, 2019

And check my optimized code at https://github.com/zibri/rand2

@Zibri
Copy link
Author

Zibri commented Apr 6, 2019

Or also:

#ifndef ZIBRI192_H
#define ZIBRI192_H

/* Modified by D. Lemire, August 2017 */
#include "splitmix64.h"
#include <stdint.h>

// state for zibri192
uint64_t zibri192_s[3];


static inline uint64_t rotr(const uint64_t x, int k) {
  return (x >> k) | (x << (64 - k));
}


// call this one before calling zibri192
static inline void zibri192_seed(uint64_t seed) {
  zibri192_s[0] = splitmix64_stateless(seed);
  zibri192_s[1] = splitmix64_stateless(seed + 1);
  zibri192_s[2] = splitmix64_stateless(seed + 2);
}

// returns random number, modifies zibri192_s
static inline uint64_t zibri192(void) {
  const uint64_t s0 = zibri192_s[0];
  const uint64_t s1 = zibri192_s[1];
  const uint64_t s2 = zibri192_s[2];

  zibri192_s[0] = rotr(s0 + s1 + s2,16);
  zibri192_s[1] = s0;
  zibri192_s[2] = s1;

  return zibri192_s[0];
}

#endif // ZIBRI192_H

@lemire
Copy link
Owner

lemire commented Apr 8, 2019

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants