Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::Random Class Reference

#include <gtest-internal.h>

Public Member Functions

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

Static Public Attributes

static const UInt32 kMaxRange = 1u << 31
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Random()

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

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

739: state_(seed) {}

Member Function Documentation

◆ Generate()

UInt32 Random::Generate ( UInt32 range)

Definition at line 319 of file gtest.cc.

319 {
320 // These constants are the same as are used in glibc's rand(3).
321 // Use wider types than necessary to prevent unsigned overflow diagnostics.
322 state_ = static_cast<UInt32>(1103515245ULL*state_ + 12345U) % kMaxRange;
323
324 GTEST_CHECK_(range > 0)
325 << "Cannot generate a number in the range [0, 0).";
326 GTEST_CHECK_(range <= kMaxRange)
327 << "Generation of a number in [0, " << range << ") was requested, "
328 << "but this can only generate numbers in [0, " << kMaxRange << ").";
329
330 // Converting via modulus introduces a bit of downward bias, but
331 // it's simple, and a linear congruential generator isn't too good
332 // to begin with.
333 return state_ % range;
334}
static const UInt32 kMaxRange
#define GTEST_CHECK_(condition)
TypeWithSize< 4 >::UInt UInt32

◆ Reseed()

void testing::internal::Random::Reseed ( UInt32 seed)
inline

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

741{ state_ = seed; }
Here is the caller graph for this function:

Member Data Documentation

◆ kMaxRange

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

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


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