proxygen
testing::internal::Random Class Reference

#include <gtest-internal.h>

Public Member Functions

 Random (UInt32 seed)
 
void Reseed (UInt32 seed)
 
UInt32 Generate (UInt32 range)
 
 Random (UInt32 seed)
 
void Reseed (UInt32 seed)
 
UInt32 Generate (UInt32 range)
 
 Random (UInt32 seed)
 
void Reseed (UInt32 seed)
 
UInt32 Generate (UInt32 range)
 

Static Public Attributes

static const UInt32 kMaxRange = 1u << 31
 

Private Member Functions

 GTEST_DISALLOW_COPY_AND_ASSIGN_ (Random)
 
 GTEST_DISALLOW_COPY_AND_ASSIGN_ (Random)
 
 GTEST_DISALLOW_COPY_AND_ASSIGN_ (Random)
 

Private Attributes

UInt32 state_
 

Detailed Description

Definition at line 752 of file gtest-internal.h.

Constructor & Destructor Documentation

testing::internal::Random::Random ( UInt32  seed)
inlineexplicit

Definition at line 756 of file gtest-internal.h.

756 : state_(seed) {}
static const int seed
testing::internal::Random::Random ( UInt32  seed)
inlineexplicit

Definition at line 756 of file gtest-internal.h.

756 : state_(seed) {}
static const int seed
testing::internal::Random::Random ( UInt32  seed)
inlineexplicit

Definition at line 756 of file gtest-internal.h.

756 : state_(seed) {}
static const int seed

Member Function Documentation

UInt32 Random::Generate ( UInt32  range)

Definition at line 311 of file gtest.cc.

References GTEST_CHECK_, and folly::gen::range().

Referenced by testing::GetDefaultFilter(), operator<<(), testing::internal::ShuffleRange(), and testing::internal::GTestFlagSaver::~GTestFlagSaver().

311  {
312  // These constants are the same as are used in glibc's rand(3).
313  state_ = (1103515245U*state_ + 12345U) % kMaxRange;
314 
315  GTEST_CHECK_(range > 0)
316  << "Cannot generate a number in the range [0, 0).";
318  << "Generation of a number in [0, " << range << ") was requested, "
319  << "but this can only generate numbers in [0, " << kMaxRange << ").";
320 
321  // Converting via modulus introduces a bit of downward bias, but
322  // it's simple, and a linear congruential generator isn't too good
323  // to begin with.
324  return state_ % range;
325 }
static const UInt32 kMaxRange
Gen range(Value begin, Value end)
Definition: Base.h:467
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1295
UInt32 testing::internal::Random::Generate ( UInt32  range)
UInt32 testing::internal::Random::Generate ( UInt32  range)
testing::internal::Random::GTEST_DISALLOW_COPY_AND_ASSIGN_ ( Random  )
private
testing::internal::Random::GTEST_DISALLOW_COPY_AND_ASSIGN_ ( Random  )
private
testing::internal::Random::GTEST_DISALLOW_COPY_AND_ASSIGN_ ( Random  )
private
void testing::internal::Random::Reseed ( UInt32  seed)
inline

Definition at line 758 of file gtest-internal.h.

References GTEST_DISALLOW_COPY_AND_ASSIGN_, folly::gen::range(), and seed.

758 { state_ = seed; }
static const int seed
void testing::internal::Random::Reseed ( UInt32  seed)
inline

Definition at line 758 of file gtest-internal.h.

References folly::gen::range(), and seed.

Referenced by operator<<(), and testing::internal::UnitTestImpl::RunAllTests().

758 { state_ = seed; }
static const int seed
void testing::internal::Random::Reseed ( UInt32  seed)
inline

Definition at line 758 of file gtest-internal.h.

References GTEST_DISALLOW_COPY_AND_ASSIGN_, folly::gen::range(), and seed.

758 { state_ = seed; }
static const int seed

Member Data Documentation

static const UInt32 Random::kMaxRange = 1u << 31
static

Definition at line 754 of file gtest-internal.h.

Referenced by operator<<().

UInt32 Random::state_
private

Definition at line 765 of file gtest-internal.h.


The documentation for this class was generated from the following files: