Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::seed_seq

      From cppreference.com
      <cpp‎ |numeric‎ |random
       
       
       
      Pseudo-random number generation
       
       
      Defined in header<random>
      class seed_seq;
      (since C++11)

      std::seed_seq consumes a sequence of integer-valued data and produces a requested number of 32-bit unsigned integer values, based on the consumed data. The produced values are distributed over the entire 32-bit range even if the consumed values are close.

      It provides a way to seed a large number of random number engines or to seed a generator that requires a lot of entropy, given a small seed or a poorly distributed initial seed sequence.

      std::seed_seq meets the requirements ofSeedSequence.

      Contents

      [edit]Nested types

      Type Definition
      result_typestd::uint_least32_t

      [edit]Data members

      Member Description
      std::vector<result_type>v the underlying seed sequence
      (exposition-only member object*)

      [edit]Member functions

      constructs and seeds thestd::seed_seq object
      (public member function)
      operator=
      [deleted]
      std::seed_seq is not assignable
      (public member function)
      calculates the bias-eliminated, evenly distributed 32-bit values
      (public member function)
      obtains the number of stored 32-bit values
      (public member function)
      copies all stored 32-bit values
      (public member function)

      [edit]Example

      Run this code
      #include <cstdint>#include <iostream>#include <random> int main(){    std::seed_seq seq{1,2,3,4,5};std::vector<std::uint32_t> seeds(10);    seq.generate(seeds.begin(), seeds.end());for(std::uint32_t n: seeds)std::cout<< n<<'\n';}

      Possible output:

      4204997637424653386618560490021129615051690460811107577151146783058390410907815341234381495905678
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/seed_seq&oldid=177242"

      [8]ページ先頭

      ©2009-2025 Movatter.jp