Skip to content

ARandom#

Pseudo-random number generator.

Header:#include <AUI/Util/ARandom.h>
CMake:aui_link(my_target PUBLIC aui::core)

Detailed Description#

Wraps a std::default_random_engine seeded on construction, with shortcuts for common value types:

ARandom random;
int i = random.nextInt();
float f = random.nextFloat(0.f, 1.f);
AUuid id = random.nextUuid();
AByteBuffer salt = random.nextBytes(16);

Warning

ARandom is not suitable for cryptographic purposes.

Examples#

examples/app/minesweeper/src/MinesweeperWindow.cpp

Minesweeper Game — Minesweeper game implementation driven by ass.

        }

        mBombsPlanted = true;

        ARandom r;
        for (int i = 0; i < mBombs;) {
            int x = r.nextInt() % mFieldColumns;
            int y = r.nextInt() % mFieldRows;

            if (fieldAt(x, y) == FieldCell::EMPTY) {