<commit_before>/******************************************************************************
 ** Copyright (c) 2010 Seed Developers
 ** All rights reserved
 ** Contact: <EMAIL>
 ** Website: http://www.seedframework.org

 ** This file is part of the Seed Framework.

 ** Commercial Usage
 ** Seed Framework is available under proprietary license for those who cannot,
 ** or choose not to, use LGPL and GPL code in their projects (eg. iPhone,
 ** Nintendo Wii and others).

 ** GNU Lesser General Public License Usage
 ** Alternatively, this file may be used under the terms of the GNU Lesser
 ** General Public License version 2.1 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file.  Please review the following information to
 ** ensure the GNU Lesser General Public License version 2.1 requirements
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
 ** In addition, as a special exception, Seed developers gives you certain
 ** additional rights. These rights are described in the Seed Framework LGPL
 ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
 ** package.
 **
 ** If you have questions regarding the use of this file, please contact
 ** Seed developers at <EMAIL>.
 **
 *****************************************************************************/

/*! \file Rand.cpp
	\author	<NAME>
	\brief Pseudo random number generator
*/

#include "Rand.h"
#include <math.h>

namespace Seed {

SEED_SINGLETON_DEFINE(Rand);

Rand::Rand()
	: iSeed(0)
{
}

Rand::~Rand()
{
}

INLINE void Rand::Initialize(u32 seed)
{
	if (!seed)
		iSeed = RAND;
	else
		iSeed = seed;
}

INLINE u32 Rand::Get(u32 max)
{
	return this->Get(0, max);
}

INLINE f32 Rand::Get(f32 max)
{
	return this->Get(0, max);
}

INLINE u32 Rand::Get(u32 min, u32 max)
{

	iSeed = 214013 * iSeed + 2531011;
	return min + (iSeed ^ iSeed >> 15) % (max - min);

	//return min + (RAND >> 15) % (max - min);
}

INLINE f32 Rand::Get(f32 min, f32 max)
{

	iSeed = 214013 * iSeed + 2531011;
	return min + (iSeed >> 16) * (1.0f / 65535.0f) * (max - min);

	//return min + (RAND >> 16) * (1.0f / 65535.0f) * (max - min);
}

} // namespace<commit_msg>Fixed a division by zero crash when the min and max values are the same.<commit_after>/******************************************************************************
 ** Copyright (c) 2010 Seed Developers
 ** All rights reserved
 ** Contact: <EMAIL>
 ** Website: http://www.seedframework.org

 ** This file is part of the Seed Framework.

 ** Commercial Usage
 ** Seed Framework is available under proprietary license for those who cannot,
 ** or choose not to, use LGPL and GPL code in their projects (eg. iPhone,
 ** Nintendo Wii and others).

 ** GNU Lesser General Public License Usage
 ** Alternatively, this file may be used under the terms of the GNU Lesser
 ** General Public License version 2.1 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file.  Please review the following information to
 ** ensure the GNU Lesser General Public License version 2.1 requirements
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
 ** In addition, as a special exception, Seed developers gives you certain
 ** additional rights. These rights are described in the Seed Framework LGPL
 ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
 ** package.
 **
 ** If you have questions regarding the use of this file, please contact
 ** Seed developers at <EMAIL>.
 **
 *****************************************************************************/

/*! \file Rand.cpp
	\author	<NAME>
	\brief Pseudo random number generator
*/

#include "Rand.h"
#include <math.h>

namespace Seed {

SEED_SINGLETON_DEFINE(Rand);

Rand::Rand()
	: iSeed(0)
{
}

Rand::~Rand()
{
}

INLINE void Rand::Initialize(u32 seed)
{
	if (!seed)
		iSeed = RAND;
	else
		iSeed = seed;
}

INLINE u32 Rand::Get(u32 max)
{
	return this->Get(0, max);
}

INLINE f32 Rand::Get(f32 max)
{
	return this->Get(0, max);
}

INLINE u32 Rand::Get(u32 min, u32 max)
{
	if(min == max)
		return min;

	iSeed = 214013 * iSeed + 2531011;
	return min + (iSeed ^ iSeed >> 15) % (max - min);

	//return min + (RAND >> 15) % (max - min);
}

INLINE f32 Rand::Get(f32 min, f32 max)
{
	if(min == max)
		return min;

	iSeed = 214013 * iSeed + 2531011;
	return min + (iSeed >> 16) * (1.0f / 65535.0f) * (max - min);

	//return min + (RAND >> 16) * (1.0f / 65535.0f) * (max - min);
}

} // namespace
{'fraction_non_alphanumeric': 0.184216263352954, 'fraction_numerical': 0.03793328973185088, 'mean_word_length': 3.9017094017094016, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2590031', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1392, 'n_words': 541}