std::seed_seq::generate
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody> template< class RandomIt > void generate( RandomIt begin, RandomIt end ); |
(dal C++11) | |
Riempie l'
, sulla base dei dati originariamente forniti nel costruttore di questo
[begin, end) gamma con valori interi senza segno i, 0 ≤ i < 232, sulla base dei dati originariamente forniti nel costruttore di questo
seed_seq. I valori prodotti sono distribuiti sull'intera gamma 32-bit, anche se i valori iniziali erano fortemente polarizzato.Original:
Fills the range
, based on the data originally provided in the constructor of this
[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.
You can help to correct and verify the translation. Click here for instructions.
L'algoritmo utilizzato è il seguente (adattato dalla sequenza di inizializzazione del generatore di Mersenne Twister Makoto Matsumoto and Takuji Nishimura, che incorpora i miglioramenti apportati dalla 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.
You can help to correct and verify the translation. Click here for instructions.
- Se
begin == end, non fare nulla. Altrimenti,Original:Ifbegin == 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.
- Primo, impostare ogni elemento del campo di uscita al valore
0x8b8b8b8bOriginal:First, set each element of the output range to the value0x8b8b8b8bThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Trasformare gli elementi del campo di uscita secondo il seguente algoritmo: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
dove
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.
You can help to correct and verify the translation. Click here for instructions.
and n=begin-end
and s=v.size()
e
v è il contenitore privato che contiene i valori forniti in origine dal costruttore di questo oggetto 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.
You can help to correct and verify the translation. Click here for instructions.
begin[k+p] += r1begin[k+q] += r2begin[k] = r2,
dove
p=(n-t)/2Original:
where
p=(n-t)/2The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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,
begin[k+p] ^= r3begin[k+q] ^= r4begin[k]=r4
dove
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.
You can help to correct and verify the translation. Click here for instructions.
and r4=r3 - k%n
in cui tutti i calcoli vengono eseguiti modulo 232
e dove l'indicizzazione del campo di uscita (
e dove l'indicizzazione del campo di uscita (
begin[x]) è preso modulo n.Original:
where all calculations are performed modulo 232
and where the indexing of the output range (
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.
You can help to correct and verify the translation. Click here for instructions.
Parametri
| begin, end | - | mutevoli iteratori ad accesso casuale la cui
std::iterator_traits<>::value_type è di tipo intero senza segno idoneo alla conservazione di valori a 32 bitOriginal: mutable random-access iterators whose std::iterator_traits<>::value_type is an unsigned integer type suitable for storing 32-bit valuesThe 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.
|
Valore di ritorno
none, i risultati vengono scritti nel campo
[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.
You can help to correct and verify the translation. Click here for instructions.
Esempio
#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