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

wy2u0k returns [1, k] instead of [0, k) when WYHASH_CONDOM=2 #144

Open
kanak opened this issue Dec 1, 2023 · 0 comments
Open

wy2u0k returns [1, k] instead of [0, k) when WYHASH_CONDOM=2 #144

kanak opened this issue Dec 1, 2023 · 0 comments

Comments

@kanak
Copy link

kanak commented Dec 1, 2023

Please see this minimal repro:

#define WYHASH_CONDOM 2
#include "wyhash.h"
#include <stdio.h>
#include <inttypes.h>

#define K 3UL

/*
Issue: when wyhash_condom is set to 2, ::wy2u0k appears to return [1, k]
instead of [0, k) as documented.
*/
int main() {
  /* Arbitrarily chosen seed that results in value = k */
  uint64_t seed = 45914278979285;
  uint64_t rnd = wyrand(&seed);
  uint64_t value = wy2u0k(rnd, K);
  printf("Seed %" PRIu64 ": wy2u0k(%" PRIu64 ", %" PRIu64 ") returned %" PRIu64 "\n", seed, rnd, K, value);
  return value < 3;
}

/*
$ uname -a
Linux chandrian 6.5.12-300.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Nov 20 22:44:24 UTC 2023 x86_64 GNU/Linux

$ gcc --version
gcc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4)

$ gcc -o wyhash_repro_gcc wyhash_repro.c
$ ./wyhash_repro_gcc
Seed 3257711729923481466: wy2u0k(720363332234262248, 3) returned 3

$ clang --version
clang version 17.0.4 (Fedora 17.0.4-1.fc39)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang -o wyhash_repro_clang wyhash_repro.c
$ ./wyhash_repro_clang
Seed 3257711729923481466: wy2u0k(720363332234262248, 3) returned 3
*/
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

1 participant