名前空間
変種
操作

std::seed_seq::generate

提供: cppreference.com
< cpp‎ | numeric‎ | random‎ | seed seq

 
 
ニューメリックスライブラリ
一般的な数学関数
浮動小数点環境
複素数
数値配列
擬似乱数生成
コンパイル時有理数演算 (C++11)
汎用の数値演算
Original:
Generic numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iota(C++11)
accumulate
inner_product
adjacent_difference
partial_sum
 
擬似乱数生成
エンジンとエンジンアダプタ
Original:
Engines and engine adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
linear_congruential_engine(C++11)
mersenne_twister_engine(C++11)
subtract_with_carry_engine(C++11)
discard_block_engine(C++11)
independent_bits_engine(C++11)
shuffle_order_engine(C++11)
ジェネレータ
Original:
Generators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
random_device(C++11)
ディストリビューション
Original:
Distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
一様分布
Original:
Uniform distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
uniform_int_distribution(C++11)
uniform_real_distribution(C++11)
generate_canonical(C++11)
ベルヌーイ分布
Original:
Bernoulli distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bernoulli_distribution(C++11)
binomial_distribution(C++11)
negative_binomial_distribution(C++11)
geometric_distribution(C++11)
ポアソン分布
Original:
Poisson distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
poisson_distribution(C++11)
exponential_distribution(C++11)
gamma_distribution(C++11)
weibull_distribution(C++11)
extreme_value_distribution(C++11)
正規分布
Original:
Normal distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
normal_distribution(C++11)
lognormal_distribution(C++11)
chi_squared_distribution(C++11)
cauchy_distribution(C++11)
fisher_f_distribution(C++11)
student_t_distribution(C++11)
サンプリング分布
Original:
Sampling distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
discrete_distribution(C++11)
piecewise_constant_distribution(C++11)
piecewise_linear_distribution(C++11)
シードシーケンス
Original:
Seed Sequences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
seed_seq(C++11)
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rand
srand
RAND_MAX
 
std::seed_seq
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
seed_seq::seed_seq
seed_seq::generate
seed_seq::size
seed_seq::param
 
template< class RandomIt >
void generate( RandomIt begin, RandomIt end );
(C++11およびそれ以降)
符号なし整数の値を含む範囲の[begin, end)を塗りつぶしi0 ≤ i < 232
、もともとこのseed_seqのコンストラクタで提供されたデータに基づいています。生成された値は、初期値が強く偏った場合でも、全体の32ビットの範囲に分布している.
Original:
Fills the range [begin, end) with unsigned integer values i, 0 ≤ i < 232
, based on the data originally provided in the constructor of this seed_seq. The produced values are distributed over the entire 32-bit range even if the initial values were strongly biased.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
以下のアルゴリズムは(Makoto Matsumoto and Takuji Nishimura製の改良を取り入れ、Mutsuo Saito in 2007でメルセンヌツイスター発生器の初期化シーケンスから適応)が使用されます
Original:
The following algorithm is used (adapted from the initialization sequence of the Mersenne Twister generator by Makoto Matsumoto and Takuji Nishimura, incorporating the improvements made by Mutsuo Saito in 2007)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • begin == end場合は、何もしません。それ以外の場合は、
    Original:
    If begin == end, do nothing. Otherwise,
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • まず、値0x8b8b8b8bに出力範囲の各要素を設定します
    Original:
    First, set each element of the output range to the value 0x8b8b8b8b
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 次のアルゴリズムに従って出力範囲の要素を変換する:
    Original:
    Transform the elements of the output range according to the following algorithm:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

For k = 0,..., m-1

どこm=max(s+1, n)
Original:
where m=max(s+1, n)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

and n=begin-end
and s=v.size()

vは当初、このseed_seqオブジェクトのコンストラクターによって提供された値を保持するプライベートコンテナです
Original:
and v is the private container holding the values originally provided by the constructor of this seed_seq object,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  1. begin[k+p] += r1
  2. begin[k+q] += r2
  3. begin[k] = r2,
どこp=(n-t)/2
Original:
where p=(n-t)/2
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

and q=p+t
and t=(n >= 623) ? 11 : (n >= 68) ? 7 : (n >= 39) ? 5 : (n >= 7) ? 3 : (n - 1) / 2
and r1=1664525 * T(begin[k]^begin[k+p]^begin[k−1])
and T(x) = x ^ (x << 27)
and r2=r1+s if k==0, r2=r1 + k%n + v[k-1] if 0<k<=s, r2=r1 + k%n if k>s.

For k = m,..., m+n-1,

  1. begin[k+p] ^= r3
  2. begin[k+q] ^= r4
  3. begin[k]=r4
どこr3 = 1566083941 * T(begin[k]+begin[k+p]+begin[k-1])
Original:
where r3 = 1566083941 * T(begin[k]+begin[k+p]+begin[k-1])
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

and r4=r3 - k%n

すべての計算はmodulo 232
を実行され、出力範囲(begin[x])の索引付けがmodulo n取られるところどこ.
Original:
where all calculations are performed modulo 232
and where the indexing of the output range (begin[x]) is taken modulo n.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

begin, end -
そのstd::iterator_traits<>::value_type32ビット値を格納するのに適した符号なし整数型である可変ランダムアクセスイテレータ
Original:
mutable random-access iterators whose std::iterator_traits<>::value_type is an unsigned integer type suitable for storing 32-bit values
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Type requirements
-
RandomIt must meet the requirements of RandomAccessIterator.

[編集] 値を返します

なにも、結果は[begin, end)範囲に書き込まれません.
Original:
none, the results are written to the [begin, end) range.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#include <random>
#include <iostream>
 
int main()
{
    std::seed_seq seq({1,2,3,4,5});
    std::vector<std::uint32_t> seeds(10);
    seq.generate(seeds.begin(), seeds.end());
// Step 1: fill with 0x8b8b8b8b
// seeds = {2341178251, 2341178251, 2341178251, 2341178251, 2341178251,
//          2341178251, 2341178251, 2341178251, 2341178251, 2341178251 }
//
// Step 2: 
// n = 10, s = 5, t = 3, p = 3, q = 6, m = 10
//
// First iteration, k = 0; r1 = 1371501266, r2 = 1371501271
//
// seeds = {1371501271, 2341178251, 2341178251, 3712679517, 2341178251,
//          2341178251, 3712679522, 2341178251, 2341178251, 2341178251 }
//
// Iterations from k = 1 to k = 5 (r2 = r1 + k%n + v[k-1])
//
// r1 = 2786190137, 3204727651, 4173325571, 1979226628, 401983366
// r2 = 2786190139, 3204727655, 4173325577, 1979226636, 401983376
//
// seeds = {3350727907, 3188173515, 3204727655, 4173325577, 1979226636,
//           401983376, 3591037797, 2811627722, 1652921976, 2219536532 } 
//
// Iterations from k = 6 to k = 9 (r2 = r1 + k%n)
//
// r1 = 2718637909, 1378394210, 2297813071, 1608643617
// r2 = 2718637915, 1378394217, 2297813079, 1608643626
//
// seeds = { 434154821, 1191019290, 3237041891, 1256752498, 4277039715,
//          2010627002, 2718637915, 1378394217, 2297813079, 1608643626 } 
//
// Step 3
// iterations from k = 10 to k = 19, using ^= to modify the output
//
// r1 = 1615303485, 3210438310, 893477041, 2884072672, 1918321961,
// r2 = 1615303485, 3210438309, 893477039, 2884072669, 1918321957
//
// seeds = { 303093272, 3210438309,  893477039, 2884072669, 1918321957,
//          1117182731, 1772877958, 2669970405, 3182737656, 4094066935 }
//
// r1 =  423054846, 46783064, 3904109085, 1534123446, 1495905687
// r2 =  423054841, 46783058, 3904109078, 1534123438, 1495905678
//
// seeds = { 4204997637, 4246533866, 1856049002, 1129615051, 690460811,
//           1075771511,   46783058, 3904109078, 1534123438, 1495905678 }
 
    for(std::uint32_t n : seeds)
        std::cout << n << '\n';
}

Output:

4204997637
4246533866
1856049002
1129615051
690460811
1075771511
46783058
3904109078
1534123438
1495905678