.. _program_listing_file_src_navtk_experimental_random.hpp: Program Listing for File random.hpp =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/navtk/experimental/random.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include #include namespace navtk { // TODO #613: Remove random number generation support from experimental namespace once rng is // verified. namespace experimental { void s_rand(uint64_t seed); void s_rand_local(uint64_t const seed); double rand_local(); double as_double(uint64_t v); inline uint64_t pcg_random_r(); class RandomNumberGenerator { public: RandomNumberGenerator() = default; RandomNumberGenerator(const RandomNumberGenerator&) = delete; RandomNumberGenerator(RandomNumberGenerator&&) = delete; RandomNumberGenerator& operator=(const RandomNumberGenerator&) = delete; RandomNumberGenerator& operator=(RandomNumberGenerator&&) = delete; virtual ~RandomNumberGenerator() = default; virtual void seed(uint64_t seed) = 0; virtual double rand() = 0; Vector rand(int num); Matrix rand(int num_rows, int num_cols); virtual double rand_n(); Vector rand_n(int num); Matrix rand_n(int num_rows, int num_cols); private: double spare = 0.0; bool has_spare = false; }; template class RandomNumberEngineWrapper : public RandomNumberGenerator { public: TEngine engine; std::uniform_real_distribution converter; RandomNumberEngineWrapper() : RandomNumberGenerator(), engine(), converter(0.0, 1.0) {} double rand() override { return converter(engine); } void seed(uint64_t seed) override { engine.seed(seed); } }; class LocalEngineWrapper : public RandomNumberGenerator { public: double rand() override { return rand_local(); } void seed(uint64_t seed) override { s_rand_local(seed); } }; not_null> get_global_rng(); void set_global_rng(not_null> randomness); template void set_global_rng() { set_global_rng(std::make_shared>()); } double rand(); Vector rand(int num); Matrix rand(int num_rows, int num_cols); double rand_n(); Vector rand_n(int num); Matrix rand_n(int num_rows, int num_cols); } // namespace experimental } // namespace navtk