Go to the source code of this file.
|
namespace | vita |
| The main namespace for the project.
|
|
- Copyright
- Copyright (C) 2011-2024 EOS di Manlio Morini.
- 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.
◆ 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] | base | a base number |
[in] | width | maximum distance from the base number |
[in] | n | modulus |
- 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] | s | the 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.
◆ 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.