std::experimental::randint(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::experimental::randint(3) πŸ’–

okay so bestie, this is a C++ Standard Library man page, section 3, and the manual name is literally std::experimental::randint(3) β€” folding that in right here so you know exactly what's up. 🫢

🌸 NAME 🌸

  • std::experimental::randint β€” std::experimental::randint, no cap. πŸ’…

✨ Synopsis ✨

Defined in header <experimental/random>:

template< class IntType >                 (library fundamentals TS v2)
IntType randint( IntType a, IntType b );

Generates a random integer in the closed interval [a, b]. it's giving random but make it official. πŸŽ€

πŸ“ Parameters πŸ“

  • a, b β€” integer values specifying the range. yes bestie, both of them are integers, and together they set the range. πŸ’–

🫢 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. literally random, but scoped to your thread, iykyk. ✨

πŸ’€ 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. no cap, those are the only approved types. 🚫
  • The behavior is undefined if a > b. so do NOT let a be bigger than b β€” that's undefined behavior territory, and we do not stan that. 😭

🌈 Example 🌈

// Run this code β€” yes, go run it bestie:

        #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

πŸ‘€ See also πŸ‘€

  • reseed β€” reseeds the per-thread random engine (function). so if you need a fresh vibe, that's your girl. πŸ’…

mwah πŸ’‹ β€” source/version/date: http://cppreference.com, 2024.06.10, and this iconic page is std::experimental::randint(3). periodt. 🌟

πŸ“¦ where this page comes from