Vita
Namespaces | Functions | Variables
random.cc File Reference

Go to the source code of this file.

Namespaces

namespace  vita
 The main namespace for the project.
 

Functions

void vita::random::randomize ()
 Sets the shared engine to an unpredictable state. More...
 
unsigned vita::random::ring (unsigned base, unsigned width, unsigned n)
 Returns a random number in a modular arithmetic system. More...
 
void vita::random::seed (unsigned s)
 Initalizes the random number generator. More...
 

Variables

engine_t vita::random::engine
 The shared random engine generator. More...
 

Detailed Description

Remarks
This file is part of VITA.
License\n
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/

Definition in file random.cc.

Function Documentation

◆ randomize()

void vita::random::randomize ( )

Sets the shared engine to an unpredictable state.

Definition at line 50 of file random.cc.

◆ ring()

unsigned vita::random::ring ( unsigned  base,
unsigned  width,
unsigned  n 
)

Returns a random number in a modular arithmetic system.

Parameters
[in]basea base number
[in]widthmaximum distance from the base number
[in]nmodulus
Returns
a random number in the [base - width/2, base + width/2] mod n interval

Definition at line 65 of file random.cc.

◆ seed()

void vita::random::seed ( unsigned  s)

Initalizes the random number generator.

Parameters
[in]sthe seed for the random number generator

The seed is used to initalize the random number generator. With the same seed the numbers produced will be the same every time the program is run.

Note
A common method to seed a PRNG is using the current time (std::time(0)). It works... but the preferred way in Vita is the randomize method (which is based on std::random_device).

Definition at line 42 of file random.cc.

Variable Documentation

◆ engine

engine_t vita::random::engine

The shared random engine generator.

The numbers produced will be the same every time the program is run. Use the randomize / seed functions for randomization.

Definition at line 27 of file random.cc.