Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::RandomEngine Class Reference
Inheritance diagram for duckdb::RandomEngine:
Collaboration diagram for duckdb::RandomEngine:

Public Member Functions

 RandomEngine (int64_t seed=-1)
double NextRandom (double min, double max)
 Generate a random number between min and max.
double NextRandom ()
 Generate a random number between 0 and 1.
double NextRandom32 ()
 Generate a random number between 0 and 1, using 32-bits as a base.
double NextRandom32 (double min, double max)
uint32_t NextRandomInteger32 (uint32_t min, uint32_t max)
uint32_t NextRandomInteger ()
uint32_t NextRandomInteger (uint32_t min, uint32_t max)
uint64_t NextRandomInteger64 ()
void SetSeed (uint64_t seed)
void RandomData (duckdb::data_ptr_t data, duckdb::idx_t len)

Static Public Member Functions

static RandomEngine & Get (ClientContext &context)

Public Attributes

mutex lock

Private Attributes

unique_ptr< RandomState > random_state

Constructor & Destructor Documentation

◆ RandomEngine()

duckdb::RandomEngine::RandomEngine ( int64_t seed = -1)
explicit
97361 : random_state(make_uniq<RandomState>()) {
97362 if (seed < 0) {
97363#ifdef __linux__
97364 idx_t random_seed = 0;
97365 int result = -1;
97366#if defined(SYS_getrandom)
97367 result = static_cast<int>(syscall(SYS_getrandom, &random_seed, sizeof(random_seed), 0));
97368#endif
97369 if (result == -1) {
97370 // Something went wrong with the syscall, we use chrono
97371 const auto now = std::chrono::high_resolution_clock::now();
97372 random_seed = now.time_since_epoch().count();
97373 }
97374 random_state->pcg.seed(random_seed);
97375#else
97376 random_state->pcg.seed(pcg_extras::seed_seq_from<std::random_device>());
97377#endif
97378 } else {
97379 random_state->pcg.seed(NumericCast<uint64_t>(seed));
97380 }
97381}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ~RandomEngine()

duckdb::RandomEngine::~RandomEngine ( )
97383 {
97384}

Member Function Documentation

◆ NextRandom() [1/2]

double duckdb::RandomEngine::NextRandom ( double min,
double max )

Generate a random number between min and max.

97386 {
97387 D_ASSERT(max >= min);
97388 return min + (NextRandom() * (max - min));
97389}
double NextRandom()
Generate a random number between 0 and 1.
Definition duckdb.cpp:97391
static softfloat min()
static softfloat max()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextRandom() [2/2]

double duckdb::RandomEngine::NextRandom ( )

Generate a random number between 0 and 1.

97391 {
97392 auto uint64 = NextRandomInteger64();
97393 return std::ldexp(uint64, -64);
97394}
uint64_t uint64
Here is the caller graph for this function:

◆ NextRandom32() [1/2]

double duckdb::RandomEngine::NextRandom32 ( )

Generate a random number between 0 and 1, using 32-bits as a base.

97401 {
97402 auto uint32 = NextRandomInteger();
97403 return std::ldexp(uint32, -32);
97404}

◆ NextRandom32() [2/2]

double duckdb::RandomEngine::NextRandom32 ( double min,
double max )
97396 {
97397 D_ASSERT(max >= min);
97398 return min + (NextRandom32() * (max - min));
97399}
double NextRandom32()
Generate a random number between 0 and 1, using 32-bits as a base.
Definition duckdb.cpp:97401

◆ NextRandomInteger32()

uint32_t duckdb::RandomEngine::NextRandomInteger32 ( uint32_t min,
uint32_t max )
97418 {
97419 return min + static_cast<uint32_t>(NextRandom32() * double(max - min));
97420}
::uint32_t uint32_t

◆ NextRandomInteger() [1/2]

uint32_t duckdb::RandomEngine::NextRandomInteger ( )
97406 {
97407 return random_state->pcg();
97408}

◆ NextRandomInteger() [2/2]

uint32_t duckdb::RandomEngine::NextRandomInteger ( uint32_t min,
uint32_t max )
97414 {
97415 return min + static_cast<uint32_t>(NextRandom() * double(max - min));
97416}

◆ NextRandomInteger64()

uint64_t duckdb::RandomEngine::NextRandomInteger64 ( )
97410 {
97411 return (static_cast<uint64_t>(NextRandomInteger()) << UINT64_C(32)) | static_cast<uint64_t>(NextRandomInteger());
97412}
::uint64_t uint64_t

◆ SetSeed()

void duckdb::RandomEngine::SetSeed ( uint64_t seed)
97422 {
97423 random_state->pcg.seed(seed);
97424}

◆ RandomData()

void duckdb::RandomEngine::RandomData ( duckdb::data_ptr_t data,
duckdb::idx_t len )
97426 {
97427 while (len) {
97428 const auto random_integer = NextRandomInteger();
97429 const auto next = duckdb::MinValue<duckdb::idx_t>(len, sizeof(random_integer));
97430 memcpy(data, duckdb::const_data_ptr_cast(&random_integer), next);
97431 data += next;
97432 len -= next;
97433 }
97434}

◆ Get()

RandomEngine & duckdb::RandomEngine::Get ( ClientContext & context)
static
274337 {
274338 return *ClientData::Get(context).random_engine;
274339}

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