Celeritas  0.5.0-86+4a8eea4
Public Member Functions | Static Public Member Functions | List of all members
celeritas::test::SequenceEngine Class Reference

"Random" number generator that returns a sequence of values. More...

#include <SequenceEngine.hh>

Public Types

Type aliases
using result_type = std::uint32_t
 
using VecResult = std::vector< result_type >
 
using LimitsT = std::numeric_limits< result_type >
 
using size_type = VecResult::size_type
 

Public Member Functions

 SequenceEngine (VecResult values)
 Construct from a sequence of integers (the sequence to reproduce).
 
result_type operator() ()
 Get the next random value in the sequence. More...
 
size_type count () const
 
size_type max_count () const
 

Static Public Member Functions

static SequenceEngine from_reals (Span< double const > values)
 Construct a sequence to nearly reproduce the given stream of reals. More...
 
static SequenceEngine from_reals (std::initializer_list< double > values)
 Construct a sequence to nearly reproduce the given stream of reals.
 
Engine limits
static constexpr result_type min ()
 
static constexpr result_type max ()
 

Detailed Description

"Random" number generator that returns a sequence of values.

This is useful for testing algorithms that expect a random stream on the host: you can specify the sequence of values to return. When the sequence is used up, the next operator call will raise an exception.

The factory function SequenceEngine::from_reals will create an integer sequence that exactly reproduces the given real numbers (which must be in the half-open interval \( [0, 1) \)) using the generate_canonical function.

Member Function Documentation

◆ from_reals()

SequenceEngine celeritas::test::SequenceEngine::from_reals ( Span< double const >  values)
inlinestatic

Construct a sequence to nearly reproduce the given stream of reals.

Values below 1e-64 will not be represented. Furthermore, some other values (see the RngEngine unit test) will not be exactly reproduced. All input values must be bounded in \( [0, 1) \) .

◆ operator()()

auto celeritas::test::SequenceEngine::operator() ( )
inline

Get the next random value in the sequence.

This is designed to throw an error rather than dereference an off-the-end iterator even when debugging is disabled, since this class is only used inside of tests.


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