#include <math.h>
#include <string.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include "ieee754.h"
-#include "../log.h"
#include "zipf.h"
#include "../minmax.h"
#include "../hash.h"
else
val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
+ val--;
+
if (!zs->disable_hash)
- return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges;
+ val = __hash_u64(val);
- return (val - 1 + zs->rand_off) % zs->nranges;
+ return (val + zs->rand_off) % zs->nranges;
}
void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
unsigned long long pareto_next(struct zipf_state *zs)
{
double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
- unsigned long long n = zs->nranges - 1;
+ unsigned long long n;
+
+ n = (zs->nranges - 1) * pow(rand, zs->pareto_pow);
if (!zs->disable_hash)
- return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges;
+ n = __hash_u64(n);
- return (unsigned long long) (n * pow(rand, zs->pareto_pow) + zs->rand_off) % zs->nranges;
+ return (n + zs->rand_off) % zs->nranges;
}
void zipf_disable_hash(struct zipf_state *zs)