My old project for strange attractors
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
//
|
|
|
|
// Random.hpp
|
|
|
|
// AwesomeAttract0r
|
|
|
|
//
|
|
|
|
// Created by Joshua Moerman on 12/28/11.
|
|
|
|
// Copyright (c) 2011 Vadovas. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef AwesomeAttract0r_Random_hpp
|
|
|
|
#define AwesomeAttract0r_Random_hpp
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// capital because random() was already defined :(
|
|
|
|
namespace Random {
|
|
|
|
// used as dummy paramter
|
|
|
|
struct parameters {};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
All uniform distributions are inclusive (ie [min, max]).
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value && std::is_floating_point<T>::value, T>::type uniform(T min, T max){
|
|
|
|
return min + (rand() / (T) RAND_MAX) * (max - min);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value && std::is_integral<T>::value, T>::type uniform(T min, T max){
|
|
|
|
return min + (rand() % (max - min + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::vector<T> make_vector(T min, T max, size_t number_of_elements){
|
|
|
|
std::vector<T> ret;
|
|
|
|
for (size_t i = 0; i < number_of_elements; ++i) {
|
|
|
|
ret.push_back(uniform(min, max));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::pair<T, T> in_circle(T radius){
|
|
|
|
T r = uniform<T>(0, radius);
|
|
|
|
T t = uniform<T>(-M_PI, M_PI);
|
|
|
|
return std::make_pair(r * std::cos(t), r * std::sin(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace random
|
|
|
|
|
|
|
|
#endif
|