// // 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 // capital because random() was already defined :( namespace Random { // used as dummy paramter struct parameters {}; /*! All uniform distributions are inclusive (ie [min, max]). */ template typename std::enable_if::value && std::is_floating_point::value, T>::type uniform(T min, T max){ return min + (rand() / (T) RAND_MAX) * (max - min); } template typename std::enable_if::value && std::is_integral::value, T>::type uniform(T min, T max){ return min + (rand() % (max - min + 1)); } template std::vector make_vector(T min, T max, size_t number_of_elements){ std::vector ret; for (size_t i = 0; i < number_of_elements; ++i) { ret.push_back(uniform(min, max)); } return ret; } template std::pair in_circle(T radius){ T r = uniform(0, radius); T t = uniform(-M_PI, M_PI); return std::make_pair(r * std::cos(t), r * std::sin(t)); } } // namespace random #endif