Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.

Class rand48



// In header: <boost/random/linear_congruential.hpp>

class rand48 {
  // types
  typedef int32_t result_type;

  // construct/copy/destruct
  template<typename T> rand48(T = 1);
  template<typename It> rand48(It &, It);

  // public member functions
  int32_t min() const;
  int32_t max() const;
  template<typename T> void seed(T = 1) ;
  template<typename It> void seed(It &, It) ;
  int32_t operator()() ;

  // public static functions
  static bool validation(int32_t) ;
  static const bool has_fixed_range;
  static const int32_t min_value;
  static const int32_t max_value;


Class rand48 models a pseudo-random number generator . It uses the linear congruential algorithm with the parameters a = 0x5DEECE66D, c = 0xB, m = 2**48. It delivers identical results to the lrand48() function available on some systems (assuming lcong48 has not been called).

It is only available on systems where uint64_t is provided as an integral type, so that for example static in-class constants and/or enum definitions with large uint64_t numbers work.

rand48 public construct/copy/destruct

  1. template<typename T> rand48(T x0 = 1);

    If T is an integral type smaller than int46_t, constructs a rand48 generator with x(0) := (x0 << 16) | 0x330e. Otherwise constructs a rand48 generator with x(0) = x0.

  2. template<typename It> rand48(It & first, It last);

rand48 public member functions

  1. int32_t min() const;

    Returns the smallest value that the generator can produce

  2. int32_t max() const;

    Returns the largest value that the generator can produce

  3. template<typename T> void seed(T x0 = 1) ;

    If T is an integral type smaller than int46_t, changes the current value x(n) of the generator to (x0 << 16) | 0x330e. Otherwise changes the current value x(n) to x0.

  4. template<typename It> void seed(It & first, It last) ;
  5. int32_t operator()() ;

    Returns the next value of the generator.

rand48 public static functions

  1. static bool validation(int32_t x) ;