Utility class for generating pseudo-random numbers. More...
#include <Randomizer.hpp>
Static Public Member Functions | |
static void | SetSeed (unsigned int seed) |
Set a new seed for the generator. | |
static unsigned int | GetSeed () |
Get the current seed of the generator. | |
static float | Random (float begin, float end) |
Get a random float number in a given range. | |
static int | Random (int begin, int end) |
Get a random integer number in a given range. |
Utility class for generating pseudo-random numbers.
sf::Randomizer generates pseudo-random numbers using the standard library.
Usage example:
int x1 = sf::Randomizer::Random(0, 6); float x2 = sf::Randomizer::Random(0.f, 1.f);
Note that, unlike the standard rand() function, you don't have to initialize the seed before using this class. SFML does it for you, so that you will automatically get different results for every execution of the program.
The SetSeed and GetSeed functions are provided mainly for being able to reproduce the same set of numbers in a recorded sequence. This is useful when implementing replays, for example.
The technique used by sf::Randomizer for getting random numbers is not the most accurate: some numbers may have a slightly higher probability than others, under certain circumstancies. This doesn't matter in 99.9% of situations, but if you really need a generator which is mathematically more robust you should use another library for that part (see boost.random).
Definition at line 40 of file Randomizer.hpp.
unsigned int sf::Randomizer::GetSeed | ( | ) | [static] |
Get the current seed of the generator.
Definition at line 63 of file Randomizer.cpp.
int sf::Randomizer::Random | ( | int | begin, | |
int | end | |||
) | [static] |
Get a random integer number in a given range.
begin | Beginning of the range | |
end | End of the range |
Definition at line 81 of file Randomizer.cpp.
float sf::Randomizer::Random | ( | float | begin, | |
float | end | |||
) | [static] |
Get a random float number in a given range.
begin | Beginning of the range | |
end | End of the range |
Definition at line 70 of file Randomizer.cpp.
void sf::Randomizer::SetSeed | ( | unsigned int | seed | ) | [static] |
Set a new seed for the generator.
Using a known seed allows you to reproduce the same sequence of random numbers.
seed | Number to use as the seed |
Definition at line 55 of file Randomizer.cpp.