Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::randint

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
      Defined in header<experimental/random>
      template<class IntType>
      IntType randint( IntType a, IntType b);
      (library fundamentals TS v2)

      Generates a random integer in the closed interval[a, b].

      Contents

      [edit]Parameters

      a, b - integer values specifying the range

      [edit]Return value

      A random integeri in the closed interval[a, b], produced using a thread-local instance ofstd::uniform_int_distribution<IntType> invoked with theper-thread random number engine.

      [edit]Remarks

      IfIntType is not one ofshort,int,long,longlong,unsignedshort,unsignedint,unsignedlong, orunsignedlonglong, the program is ill-formed.

      The behavior is undefined ifa> 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

      [edit]See also

      reseeds the per-thread random engine
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/randint&oldid=155222"

      [8]ページ先頭

      ©2009-2025 Movatter.jp