<commit_before>#include "Helper.h"
#include "Exceptions.h"
#include "cmath"
#include "time.h"
#include <QDir>
#include <QCoreApplication>
#include <QDateTime>

double Helper::randomNumber(double min, double max)
{
	double r = (double)rand() / (double)RAND_MAX;
	return min + r * (max - min);
}

QString Helper::randomString(int length, const QString& chars)
{
	//initialize random number generator
	//initialized only once - otherwise two calls in the same second produce to the same random string
	static bool is_initialized = false;
	if (!is_initialized)
	{
		int seconds = time(NULL);
		int milliseconds = QTime::currentTime().msec();
		int process_id = QCoreApplication::applicationPid();
		srand(seconds + milliseconds + process_id);
		is_initialized = true;
	}

	//create random string
	QString output;
	for (int i=0; i<length; ++i)
	{
		output.append(chars[rand() % (chars.length()-1)]);
	}
	return output;
}

QByteArray Helper::elapsedTime(QTime elapsed, bool only_seconds)
{
	//calculate minutes and seconds
	double s = elapsed.elapsed()/1000.0;
	double m = 0;
	if (!only_seconds)
	{
		m = floor(s/60.0);
		s -= 60.0 * m;
	}

	//create strings
	QByteArray sec = QByteArray::number(s, 'f', 3) + "s";
	QByteArray min = "";<commit_msg>Helper::randomString: srand is now called whenever a random string is generated (we need to initialize in each thread!)<commit_after>#include "Helper.h"
#include "Exceptions.h"
#include "cmath"
#include "time.h"
#include <QDir>
#include <QCoreApplication>
#include <QDateTime>

double Helper::randomNumber(double min, double max)
{
	double r = (double)rand() / (double)RAND_MAX;
	return min + r * (max - min);
}

QString Helper::randomString(int length, const QString& chars)
{
	//initialize random number generator
	int seconds = time(NULL);
	int milliseconds = QTime::currentTime().msec();
	int process_id = QCoreApplication::applicationPid();
	srand(seconds + milliseconds + process_id);

	//create random string
	QString output;
	for (int i=0; i<length; ++i)
	{
		output.append(chars[rand() % (chars.length()-1)]);
	}
	return output;
}

QByteArray Helper::elapsedTime(QTime elapsed, bool only_seconds)
{
	//calculate minutes and seconds
	double s = elapsed.elapsed()/1000.0;
	double m = 0;
	if (!only_seconds)
	{
		m = floor(s/60.0);
		s -= 60.0 * m;
	}

	//create strings
	QByteArray sec = QByteArray::number(s, 'f', 3) + "s";
	QByteArray min = "";
{'fraction_non_alphanumeric': 0.14452798663324978, 'fraction_numerical': 0.012531328320802004, 'mean_word_length': 4.66193853427896, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '849934', 'n_tokens_mistral': 870, 'n_tokens_neox': 832, 'n_words': 233}