<commit_before>/************************************************************************
* QuickProf                                                             *
* http://quickprof.sourceforge.net                                      *
* Copyright (C) 2006-2008                                               *
* <NAME> (http://www.tylerstreeter.net)                         *
*                                                                       *
* This library is free software; you can redistribute it and/or         *
* modify it under the terms of EITHER:                                  *
*   (1) The GNU Lesser General Public License as published by the Free  *
*       Software Foundation; either version 2.1 of the License, or (at  *
*       your option) any later version. The text of the GNU Lesser      *
*       General Public License is included with this library in the     *
*       file license-LGPL.txt.                                          *
*   (2) The BSD-style license that is included with this library in     *
*       the file license-BSD.txt.                                       *
*   (3) The zlib/libpng license that is included with this library in   *
*       the file license-zlib-libpng.txt.                               *
*                                                                       *
* This library is distributed in the hope that it will be useful,       *
* but WITHOUT ANY WARRANTY; without even the implied warranty of        *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
* license-LGPL.txt, license-BSD.txt, and license-zlib-libpng.txt for    *
* more details.                                                         *
************************************************************************/

#include "../quickprof.h"

int randomIntUniform(int min, int max)
{
	// Note: rand() isn't a very good generator, but it's good enough for 
	// simple tasks that only require a few thousand values.

	int range = max - min;
	int randValue = rand();
	int randMaxValue = RAND_MAX;
	while (randMaxValue < range)
	{
		// Increase the random value range until we reach the desired 
		// range.
		randValue = randValue * RAND_MAX;
		randMaxValue = randMaxValue * RAND_MAX;
		if (randValue < randMaxValue)
		{
			randValue += rand();
		}
	}

	// Get a uniform random real value from [0, 1).
	double zeroToOneHalfOpen = randValue / (randMaxValue + 1.0);

	// The [0, 1) value times (max - min + 1) gives each integer within 
	// [0, max - min] an equal chance of being chosen.
	return min + int((range + 1) * zeroToOneHalfOpen);
}

void approxDelay(int milliseconds)
{
	int spread = (int)(0.15 * (double)milliseconds);
	int delay = milliseconds + randomIntUniform(-spread, spread);<commit_msg>Added missing <cstdlib> to test.cpp for std::rand() function.<commit_after>/************************************************************************
* QuickProf                                                             *
* http://quickprof.sourceforge.net                                      *
* Copyright (C) 2006-2008                                               *
* <NAME> (http://www.tylerstreeter.net)                         *
*                                                                       *
* This library is free software; you can redistribute it and/or         *
* modify it under the terms of EITHER:                                  *
*   (1) The GNU Lesser General Public License as published by the Free  *
*       Software Foundation; either version 2.1 of the License, or (at  *
*       your option) any later version. The text of the GNU Lesser      *
*       General Public License is included with this library in the     *
*       file license-LGPL.txt.                                          *
*   (2) The BSD-style license that is included with this library in     *
*       the file license-BSD.txt.                                       *
*   (3) The zlib/libpng license that is included with this library in   *
*       the file license-zlib-libpng.txt.                               *
*                                                                       *
* This library is distributed in the hope that it will be useful,       *
* but WITHOUT ANY WARRANTY; without even the implied warranty of        *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
* license-LGPL.txt, license-BSD.txt, and license-zlib-libpng.txt for    *
* more details.                                                         *
************************************************************************/

#include "../quickprof.h"

#include <cstdlib>

int randomIntUniform(int min, int max)
{
	// Note: rand() isn't a very good generator, but it's good enough for 
	// simple tasks that only require a few thousand values.

	int range = max - min;
	int randValue = std::rand();
	int randMaxValue = RAND_MAX;
	while (randMaxValue < range)
	{
		// Increase the random value range until we reach the desired 
		// range.
		randValue = randValue * RAND_MAX;
		randMaxValue = randMaxValue * RAND_MAX;
		if (randValue < randMaxValue)
		{
			randValue += rand();
		}
	}

	// Get a uniform random real value from [0, 1).
	double zeroToOneHalfOpen = randValue / (randMaxValue + 1.0);

	// The [0, 1) value times (max - min + 1) gives each integer within 
	// [0, max - min] an equal chance of being chosen.
	return min + int((range + 1) * zeroToOneHalfOpen);
}

void approxDelay(int milliseconds)
{
	int spread = (int)(0.15 * (double)milliseconds);
	int delay = milliseconds + randomIntUniform(-spread, spread);
{'fraction_non_alphanumeric': 0.13246568015689072, 'fraction_numerical': 0.008914244963451596, 'mean_word_length': 1.7062228654124458, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678182', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1325, 'n_words': 512}