ns/op | op/s | err% | total | Random u32 to base 10. w/ /utf-8 |
---|---|---|---|---|
2.71 | 369,270,304.57 | 1.4% | 0.00 | null, i.e. the rng perf |
6.98 | 143,213,409.65 | 1.6% | 0.00 | jeaiii::to_text |
9.63 | 103,842,159.92 | 0.4% | 0.01 | fmt::format_int |
21.46 | 46,606,363.07 | 2.0% | 0.01 | std::to_string |
21.56 | 46,372,782.63 | 1.1% | 0.01 | std::to_chars |
54.56 | 18,329,649.17 | 1.0% | 0.03 | std::sprintf |
576.23 | 1,735,415.94 | 0.8% | 0.35 | std::ostringstream |
To use uniform_random_value()
include/paste the header random_value.hpp
from this gist in your project; you can after simply write :
int randomInt = uniform_random_value(1, 100);
float randomFloat = uniform_random_value(1.0f, 100.0f);
double randomDouble = uniform_random_value(1.0, 100.0);
For the instance where you want a random boolean you can write :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// © Copyright 2021 Ollivier Roberge | |
#ifndef IS_CHAR_IMPL | |
#define IS_CHAR_IMPL | |
#include <type_traits> | |
template<typename T> struct is_char : std::false_type {}; | |
template<> struct is_char<char> : std::true_type {}; | |
template<> struct is_char<wchar_t> : std::true_type {}; |