public member function
<random>

std::subtract_with_carry_engine::(constructor)

(1)
explicit subtract_with_carry_engine ( result_type val = default_seed );
(2)
template <class Sseq>
explicit subtract_with_carry_engine ( Sseq& q );
Construct subtract-with-carry engine
Constructs a subtract_with_carry_engine object, and initializes its internal state sequence to pseudo-random values.

The internal state sequence is seeded either using a linear_congruential_engine generator (which is itself seeded with val) or using a seed sequence object (q).

Parameters

val
A seeding value. An entire state sequence is generated from this value using a linear_congruential_engine object.
result_type is a member type, defined as an alias of the first class template parameter (UIntType).
default_seed is a member constant, defined as 5489u.
q
A seed sequence object, such as an object of type seed_seq.
Sseq shall be a seed sequence class, with a generate member function.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// subtract_with_carry_engine example
#include <iostream>
#include <chrono>
#include <random>

int main ()
{
  typedef std::chrono::high_resolution_clock myclock;
  myclock::time_point beginning = myclock::now();

  // obtain a seed from a user string:
  std::string str;
  std::cout << "Please, enter a seed: ";
  std::getline(std::cin,str);
  std::seed_seq seed1 (str.begin(),str.end());

  // obtain a seed from the timer
  myclock::duration d = myclock::now() - beginning;
  unsigned seed2 = d.count();

  std::subtract_with_carry_engine<unsigned,24,10,24> g1 (seed1);
  std::cout << "Your seed produced: " << g1() << std::endl;

  std::subtract_with_carry_engine<unsigned,24,10,24> g2 (seed2);
  std::cout << "A time seed produced: " << g2() << std::endl;

  return 0;
}


Possible output:
Please, enter a seed: Marsaglia
A time seed produced: 15090552
Your seed produced: 3371356

Complexity

Linear on long_lag.

See also