<commit_before>#ifndef INCLUDE_AL_MATH_RANDOM_HPP
#define INCLUDE_AL_MATH_RANDOM_HPP

/*	Allocore --
	Multimedia / virtual environment application class library

	Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
	Copyright (C) 2006-2008. The Regents of the University of California (REGENTS). 
	All Rights Reserved.

	Permission to use, copy, modify, distribute, and distribute modified versions
	of this software and its documentation without fee and without a signed
	licensing agreement, is hereby granted, provided that the above copyright
	notice, the list of contributors, this paragraph and the following two paragraphs 
	appear in all copies, modifications, and distributions.

	IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
	SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
	OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
	BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
	THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
	HEREUNDER IS PROVIDED "AS IS". REGENTS HAS  NO OBLIGATION TO PROVIDE
	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


	File description:
	Various flavors of pseudo-random number generators nad distributions

	File author(s):
	<NAME>, 2006, <EMAIL>
*/


#include <time.h>							/* req'd for time() */
#include <cmath>
#include "allocore/types/al_Conversion.hpp"	/* req'd for int to float conversion */
#include "allocore/math/al_Constants.hpp"
#include "allocore/math/al_Generators.hpp"

namespace al {
namespace rnd{

class LinCon;
class MulLinCon;
class Tausworthe;
template<class RNG> class Random;


/// Get a random seed in interval [0, 4294967296)
inline static uint32_t seed(){
	static gen::RMulAdd<uint32_t> seedGen(1664525, 1013904223, time(NULL));
	return seedGen();
}


/// Random distribution generator
template <class RNG=al::rnd::Tausworthe>
class Random{
public:

	Random(){}

	Random(uint32_t seed): mRNG(seed){}

	/// Returns uniform random in [0, 1)
	float uniform(){ return al::uintToUnit<float>(mRNG()); }

	/// Returns uniform random in [0, hi)
	template <class T>
	T uniform(const T& hi){ return hi*uniform(); }
	
	/// Returns uniform random in [lo, hi)
	template <class T>
	T uniform(const T& hi, const T& lo){ return (hi-lo)*uniform() + lo; }
<commit_msg>Random: setter for seed<commit_after>#ifndef INCLUDE_AL_MATH_RANDOM_HPP
#define INCLUDE_AL_MATH_RANDOM_HPP

/*	Allocore --
	Multimedia / virtual environment application class library

	Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
	Copyright (C) 2006-2008. The Regents of the University of California (REGENTS). 
	All Rights Reserved.

	Permission to use, copy, modify, distribute, and distribute modified versions
	of this software and its documentation without fee and without a signed
	licensing agreement, is hereby granted, provided that the above copyright
	notice, the list of contributors, this paragraph and the following two paragraphs 
	appear in all copies, modifications, and distributions.

	IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
	SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
	OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
	BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
	THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
	HEREUNDER IS PROVIDED "AS IS". REGENTS HAS  NO OBLIGATION TO PROVIDE
	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


	File description:
	Various flavors of pseudo-random number generators nad distributions

	File author(s):
	<NAME>, 2006, <EMAIL>
*/


#include <time.h>							/* req'd for time() */
#include <cmath>
#include "allocore/types/al_Conversion.hpp"	/* req'd for int to float conversion */
#include "allocore/math/al_Constants.hpp"
#include "allocore/math/al_Generators.hpp"

namespace al {
namespace rnd{

class LinCon;
class MulLinCon;
class Tausworthe;
template<class RNG> class Random;


/// Get a random seed in interval [0, 4294967296)
inline static uint32_t seed(){
	static gen::RMulAdd<uint32_t> seedGen(1664525, 1013904223, time(NULL));
	return seedGen();
}


/// Random distribution generator
template <class RNG=al::rnd::Tausworthe>
class Random{
public:

	Random(){}

	Random(uint32_t seed): mRNG(seed){}

	/// Set seed
	Random& seed(uint32_t v){ mRNG.seed(v); return *this; }

	/// Returns uniform random in [0, 1)
	float uniform(){ return al::uintToUnit<float>(mRNG()); }

	/// Returns uniform random in [0, hi)
	template <class T>
	T uniform(const T& hi){ return hi*uniform(); }
	
	/// Returns uniform random in [lo, hi)
	template <class T>
	T uniform(const T& hi, const T& lo){ return (hi-lo)*uniform() + lo; }

{'fraction_non_alphanumeric': 0.0898942420681551, 'fraction_numerical': 0.021151586368977675, 'mean_word_length': 4.770621468926554, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '3293052', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1525, 'n_words': 611}