wy2u0k returns [1, k] instead of [0, k) when WYHASH_CONDOM=2
kanak opened this issue · comments
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
*/