.. _program_listing_file_gui_Utils_Utils.hpp: Program Listing for File Utils.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``gui/Utils/Utils.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include #include constexpr unsigned int hash(const char *str) { unsigned int h = 5381; // Initial hash value for (; *str != '\0'; str++) h = (h * 33) ^ (unsigned char)*str; return h; } constexpr unsigned int hash(std::string &str) { const char *tmp_str = str.c_str(); unsigned int h = 5381; // Initial hash value for (; *tmp_str != '\0'; tmp_str++) h = (h * 33) ^ (unsigned char)*tmp_str; return h; } inline float randomFloat(float min, float max) { static std::random_device rd; static std::mt19937 gen(rd()); std::uniform_real_distribution dis(min, max); return dis(gen); } inline double hashToRange(double x, double btw = 1.0) { double hashed = std::sin(x * 12.9898) * 43758.5453; return (hashed - std::floor(hashed)) - btw; }