std::experimental::randint
From cppreference.com
 
 
 < cpp | experimental 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Experimental 
 Filesystem library (filesystem TS)
 Library fundamentals (library fundamentals TS)
 Library fundamentals 2 (library fundamentals TS v2)
 Library fundamentals 3 (library fundamentals TS v3)
 Extensions for parallelism (parallelism TS)
 Extensions for parallelism 2 (parallelism TS v2)
 Extensions for concurrency (concurrency TS)
 Extensions for concurrency 2 (concurrency TS v2)
 Concepts (concepts TS)
 Ranges (ranges TS)
 Reflection (reflection TS)
 Mathematical special functions (special functions TR)
Library fundamentals v2 
 
experimental::randint
Defined in header 
 
 
<experimental/random> 
 template< class IntType >
IntType randint( IntType a, IntType b );
 
 (library fundamentals TS v2) 
IntType randint( IntType a, IntType b );
Generates a random integer in the closed interval [a, b].
[edit] Parameters
 a, b
 -
 integer values specifying the range
[edit] Return value
A random integer i in the closed interval [a, b], produced using a thread-local instance of std::uniform_int_distribution <IntType> invoked with the per-thread random number engine.
[edit] Remarks
If IntType is not one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long, the program is ill-formed.
The behavior is undefined if a > b.
[edit] Example
Run this code
#include <experimental/random> #include <iostream> int main() { int random_number = std::experimental::randint(100, 999); std::cout << "random 3-digit number: " << random_number << '\n'; }
Possible output:
random 3-digit number: 273