public member function
<random>

std::mersenne_twister_engine::discard

void discard (unsigned long long z);
Advance internal state
Advances the internal state by z notches, as if operator() was called z times, but without generating any numbers in the process.

The effects on the state sequence are the same as if the transition algorithm was applied as many times as notches advanced on subsequent elements. The transition algorithm used by the object produces a twist on the selected element as if this was x[i] in the following piece of code:

1
2
3
UIntType Mask = (1u<<w)-1, UMask= (Mask << r) & Mask, LMask = (~UMask) & Mask,
Y = (x[i]&UMask)|(x[(i+1)%n]&LMask);  // upper bits of x[i] and lower of x[i+1]
x[i]=x[(i+m)%n]^(Y>>1)^((Y&1)*a);     // mersenne twister linear transformation 

With each of the values being their corresponding class template parameters.

Note: not fully tested, plese report any inaccuracies.

Parameters

z
Number of equivalent advances.

Return value

None

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// mersenne_twister_engine::discard
#include <iostream>
#include <chrono>
#include <random>

int main ()
{
  // obtain a seed from the system clock:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  std::mt19937 generator (seed);  // mt19937 is a standard mersenne_twister_engine

  std::cout << "Random value: " << generator() << std::endl;

  generator.discard(generator.state_size);  // twist the entire state sequence

  std::cout << "Random value: " << generator() << std::endl;

  return 0;
}


Possible output:
Random value: 2025681734
Random value: 649145785

Complexity

Linear in z.

See also