<commit_before>#ifndef _RANDOM_C
#define _RANDOM_C

#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>


// Why write a simple random number generator here?
// It is the easiest way to fullfill the following requirements
// 	1. very fast, negligible memory usage
// 	2. generates the same sequence on any architecture
// 	3. do not have annoying warnings (e.g. unsafe rand() in openbsd).
// Strong non-requirements:
// 	1. cryptographicaly secure
// 	2. pass fancy statistical tests

static uint64_t lcg_knuth_seed = 0;

void lcg_knuth_srand(unsigned int x)
{
	lcg_knuth_seed = x;
}

unsigned int lcg_knuth_rand(void)
{
	lcg_knuth_seed *= 6364136223846793005;
	lcg_knuth_seed += 1442695040888963407;
	return lcg_knuth_seed;
}


static void xsrand(unsigned int seed)
{
	lcg_knuth_srand(seed);
}

static int xrand(void)
{
	return lcg_knuth_rand();
}

static double random_raw(void)
{
	return xrand();
}
<commit_msg>[c/random.c] use the best half of bits<commit_after>#ifndef _RANDOM_C
#define _RANDOM_C

#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>


// Why write a simple random number generator here?
// It is the easiest way to fullfill the following requirements
// 	1. very fast, negligible memory usage
// 	2. generates the same sequence on any architecture
// 	3. do not have annoying warnings (e.g. unsafe rand() in openbsd).
// Strong non-requirements:
// 	1. cryptographicaly secure
// 	2. pass fancy statistical tests

static uint64_t lcg_knuth_seed = 0;

void lcg_knuth_srand(uint32_t x)
{
	lcg_knuth_seed = x;
}

uint32_t lcg_knuth_rand(void)
{
	lcg_knuth_seed *= 6364136223846793005;
	lcg_knuth_seed += 1442695040888963407;
	return lcg_knuth_seed >> 32;
}


static void xsrand(unsigned int seed)
{
	lcg_knuth_srand(seed);
}

static int xrand(void)
{
	return lcg_knuth_rand();
}

static double random_raw(void)
{
	return xrand();
}

{'fraction_non_alphanumeric': 0.10089332632685234, 'fraction_numerical': 0.051497635312664214, 'mean_word_length': 4.363380281690141, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6216188', 'n_tokens_mistral': 781, 'n_tokens_neox': 715, 'n_words': 205}