public member function
<random>

std::discard_block_engine::operator()

result_type operator()();
Generate random number
Returns a new random number.

The engine's transition algorithm advances the internal counter by one. If this makes the internal counter surpass the used_block parameter (the third class template parameter, r), it calls discard on its base engine with the difference between its block_size and its used_block as argument, and resets the internal counter.

The generation algorithm simply calls its base engine's operator() and returns its value.

Overall, this function produces the same result as if defined within discard_block_engine as:
1
2
3
4
5
6
result_type operator() {
  // assuming n is the internal counter, and e the base engine object:
  if (n>=used_block) {e.discard(block_size-used_block); n=0;}
  ++n;
  return e();
}


Note: not fully tested, plese report inaccuracies.

Parameters

None

Return value

A new random number.
result_type is a member type, defined as an alias of the type of the numbers generated by the base engine.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// discard_block_engine::operator()
#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();

  // ranlux24 is a standard instantitation of discard_block_engine:
  std::ranlux24 generator (seed);
  std::cout << "Random value: " << generator() << std::endl;

  return 0;
}


Possible output:
Random value: 11370824

Complexity

Determined by the base engine.

See also