.. _program_listing_file_include_flamegpu_runtime_random_HostRandom.cuh: Program Listing for File HostRandom.cuh ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/flamegpu/runtime/random/HostRandom.cuh``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef INCLUDE_FLAMEGPU_RUNTIME_RANDOM_HOSTRANDOM_CUH_ #define INCLUDE_FLAMEGPU_RUNTIME_RANDOM_HOSTRANDOM_CUH_ #include #include "flamegpu/detail/StaticAssert.h" #include "flamegpu/simulation/detail/RandomManager.cuh" namespace flamegpu { class HostRandom { friend class HostAPI; public: template inline T uniform() const; template inline T normal() const; template inline T logNormal(T mean, T stddev) const; template inline unsigned int poisson(double mean = 1.0f) const; template inline T uniform(T min, T max) const; void setSeed(uint64_t seed); uint64_t getSeed() const; private: explicit HostRandom(detail::RandomManager &_rng) : rng(_rng) { } detail::RandomManager &rng; }; template inline T HostRandom::uniform() const { static_assert(detail::StaticAssert::_Is_RealType::value, "Invalid template argument for HostRandom::uniform()"); std::uniform_real_distribution dist(0, 1); return rng.getDistribution(dist); } template inline T HostRandom::normal() const { static_assert(detail::StaticAssert::_Is_RealType::value, "Invalid template argument for HostRandom::normal()"); std::normal_distribution dist(0, 1); return rng.getDistribution(dist); } template inline T HostRandom::logNormal(const T mean, const T stddev) const { static_assert(detail::StaticAssert::_Is_RealType::value, "Invalid template argument for HostRandom::logNormal(T mean, T stddev)"); std::lognormal_distribution dist(mean, stddev); return rng.getDistribution(dist); } template inline T HostRandom::uniform(const T min, const T max) const { static_assert(detail::StaticAssert::_Is_IntType::value, "Invalid template argument for HostRandom::uniform(T lowerBound, T max)"); std::uniform_int_distribution dist(min, max); return rng.getDistribution(dist); } template inline unsigned int HostRandom::poisson(const double mean) const { static_assert(detail::StaticAssert::_Is_IntType::value, "Invalid template argument for HostRandom::poisson(double mean)"); std::poisson_distribution dist(mean); return rng.getDistribution(dist); } template<> inline char HostRandom::uniform(const char min, const char max) const { std::uniform_int_distribution dist(min, max); return static_cast(rng.getDistribution(dist)); } template<> inline unsigned char HostRandom::uniform(const unsigned char min, const unsigned char max) const { std::uniform_int_distribution dist(min, max); return static_cast(rng.getDistribution(dist)); } template<> inline signed char HostRandom::uniform(const signed char min, const signed char max) const { std::uniform_int_distribution dist(min, max); return static_cast(rng.getDistribution(dist)); } template<> inline float HostRandom::uniform(const float min, const float max) const { std::uniform_real_distribution dist(min, max); return rng.getDistribution(dist); } template<> inline double HostRandom::uniform(const double min, const double max) const { std::uniform_real_distribution dist(min, max); return rng.getDistribution(dist); } } // namespace flamegpu #endif // INCLUDE_FLAMEGPU_RUNTIME_RANDOM_HOSTRANDOM_CUH_