<commit_before>
#include <time.h>
#include <stdlib.h>
#include <gsl/gsl_randist.h>
#include "utils.hpp"

/* Really fast random function */
static unsigned long x=123456789, y=362436069, z=521288629;

unsigned long xorshf96(void) {          //period 2^96-1
unsigned long t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;

   t = x;
   x = y;
   y = z;
   z = t ^ x ^ y;

  return z;
}

static unsigned long saltx=123456789, salty=362436069, saltz=521288629;
unsigned long seeded_xorshf96(unsigned long seed) {
    unsigned long X = saltx ^ seed << 2, Y = salty ^ seed << 13, Z = saltz ^ seed << 5;

    X ^= X << 17;
    X ^= Y >> 13;
    X ^= Z << 43;

    X ^= X >> 5;
    X ^= X >> 16;
    X ^= X >> 44;

    return X;
}

/* Returns random number between [min, max] */
size_t random(size_t min, size_t max) {
    //return rand() % (max - min + 1) + min;
    return xorshf96() % (max - min + 1) + min;
}

size_t seeded_random(size_t min, size_t max, unsigned long seed) {
    return seeded_xorshf96(seed) % (max - min + 1) + min;
}

/* Returns random number between [min, max] using various distributions */
rnd_gen_t xrandom_create(rnd_distr_t rnd_distr, int mu) {
    rnd_gen_t rnd;
    rnd.rnd_distr = rnd_distr;
    rnd.gsl_rnd = gsl_rng_alloc(gsl_rng_mt19937);
    gsl_rng_set((gsl_rng *)rnd.gsl_rnd, get_ticks());
    rnd.mu = mu;
    return rnd;
}

size_t xrandom(size_t min, size_t max) {
    rnd_gen_t rnd;
    rnd.rnd_distr = rnd_uniform_t;
    xrandom(rnd, min, max);
}

size_t xrandom(rnd_gen_t rnd, size_t min, size_t max) {
    double tmp;
    int len = (min + max) / 2;
    
    switch(rnd.rnd_distr) {
    case rnd_uniform_t:
        tmp = random(min, max);
        break;
    case rnd_normal_t:
        // Here one percent of the database is within the standard deviation
        tmp = gsl_ran_gaussian((gsl_rng*)rnd.gsl_rnd,  (double)len / rnd.mu) + (len / 2);
        break;
    };
    
    if(tmp < min)
        tmp = min;
    if(tmp > max)
        tmp = max;
    //printf("%lu\n", (size_t)tmp);
    return tmp;
}

size_t seeded_xrandom(size_t min, size_t max, unsigned long seed) {
    rnd_gen_t rnd;<commit_msg>Fix sigma calculation<commit_after>
#include <time.h>
#include <stdlib.h>
#include <gsl/gsl_randist.h>
#include "utils.hpp"

/* Really fast random function */
static unsigned long x=123456789, y=362436069, z=521288629;

unsigned long xorshf96(void) {          //period 2^96-1
unsigned long t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;

   t = x;
   x = y;
   y = z;
   z = t ^ x ^ y;

  return z;
}

static unsigned long saltx=123456789, salty=362436069, saltz=521288629;
unsigned long seeded_xorshf96(unsigned long seed) {
    unsigned long X = saltx ^ seed << 2, Y = salty ^ seed << 13, Z = saltz ^ seed << 5;

    X ^= X << 17;
    X ^= Y >> 13;
    X ^= Z << 43;

    X ^= X >> 5;
    X ^= X >> 16;
    X ^= X >> 44;

    return X;
}

/* Returns random number between [min, max] */
size_t random(size_t min, size_t max) {
    //return rand() % (max - min + 1) + min;
    return xorshf96() % (max - min + 1) + min;
}

size_t seeded_random(size_t min, size_t max, unsigned long seed) {
    return seeded_xorshf96(seed) % (max - min + 1) + min;
}

/* Returns random number between [min, max] using various distributions */
rnd_gen_t xrandom_create(rnd_distr_t rnd_distr, int mu) {
    rnd_gen_t rnd;
    rnd.rnd_distr = rnd_distr;
    rnd.gsl_rnd = gsl_rng_alloc(gsl_rng_mt19937);
    gsl_rng_set((gsl_rng *)rnd.gsl_rnd, get_ticks());
    rnd.mu = mu;
    return rnd;
}

size_t xrandom(size_t min, size_t max) {
    rnd_gen_t rnd;
    rnd.rnd_distr = rnd_uniform_t;
    xrandom(rnd, min, max);
}

size_t xrandom(rnd_gen_t rnd, size_t min, size_t max) {
    double tmp;
    int len = (min + max) / 2;
    
    switch(rnd.rnd_distr) {
    case rnd_uniform_t:
        tmp = random(min, max);
        break;
    case rnd_normal_t:
        // Here one percent of the database is within the standard deviation
        tmp = gsl_ran_gaussian((gsl_rng*)rnd.gsl_rnd,  (double)len * (double)rnd.mu / 100.0) + (len / 2);
        break;
    };
    
    if(tmp < min)
        tmp = min;
    if(tmp > max)
        tmp = max;
    //printf("%lu\n", (size_t)tmp);
    return tmp;
}

size_t seeded_xrandom(size_t min, size_t max, unsigned long seed) {
    rnd_gen_t rnd;
{'fraction_non_alphanumeric': 0.13714551371455136, 'fraction_numerical': 0.04509530450953045, 'mean_word_length': 2.622053872053872, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493025', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1762, 'n_words': 466}