Skip to main content

Random

Pick random numbers, points, directions, etc.

Summary

Functions

Name
floatnumber()
Returns a random number between 0 and 1.
floatnumber(float max)
Returns a random number between 0 and max.
floatnumber(float min, float max)
Returns a random number between min and max.
intinteger(int max)
Returns a random integer between 0 (included) and max (excluded).
intinteger(int min, int max)
Returns a random integer between min (included) and max (excluded).
size_tsize_type(size_t max)
Returns a random size_t between 0 (included) and max (excluded).
size_tsize_type(size_t min, size_t max)
Returns a random size_t between min (included) and max (excluded).
template <typename T >
const T &
among(const std::vector< T > & collection)
Randomly returns one of the elements of the collection.
glm::vec2point(const [p6::Context](/reference/Types/context) & ctx)
Returns a point inside the main canvas of the context.
glm::vec2point(const [p6::Canvas](/reference/Types/canvas) & canvas)
Returns a point inside the given canvas.
glm::vec2point()
Returns a random point in a square between (-1, -1) and (1, 1).
glm::vec2point(glm::vec2 min, glm::vec2 max)
Returns a random point in a rectangle between min and max.
glm::vec2point(float aspect_ratio)
Returns a random point in a rectangle between (-aspect_ratio, -1) and (aspect_ratio, 1).
glm::vec2direction()
Returns a random direction (vector of length 1).
Angleangle()
Returns a random angle.

Functions

number()

float number();

Returns a random number between 0 and 1.

number()

float number(float max);

Returns a random number between 0 and max.

Throws a std::invalid_argument exception if max < 0.

number()

float number(float min, float max);

Returns a random number between min and max.

Throws a std::invalid_argument exception if min > max.

integer()

int integer(int max);

Returns a random integer between 0 (included) and max (excluded).

Throws a std::invalid_argument exception if max <= 0.

integer()

int integer(int min, int max);

Returns a random integer between min (included) and max (excluded).

Throws a std::invalid_argument exception if min >= max.

size_type()

size_t size_type(size_t max);

Returns a random size_t between 0 (included) and max (excluded).

size_type()

size_t size_type(size_t min, size_t max);

Returns a random size_t between min (included) and max (excluded).

Throws a std::invalid_argument exception if min >= max.

among()

const T & among(const std::vector< T > & collection);

Randomly returns one of the elements of the collection.

Throws a std::invalid_argument exception if the collection is empty.

point()

glm::vec2 point(const [p6::Context](/reference/Types/context) & ctx);

Returns a point inside the main canvas of the context.

point()

glm::vec2 point(const [p6::Canvas](/reference/Types/canvas) & canvas);

Returns a point inside the given canvas.

point()

glm::vec2 point();

Returns a random point in a square between (-1, -1) and (1, 1).

point()

glm::vec2 point(glm::vec2 min, glm::vec2 max);

Returns a random point in a rectangle between min and max.

Throws a std::invalid_argument exception if min.x > max.x || min.y > max.y.

point()

glm::vec2 point(float aspect_ratio);

Returns a random point in a rectangle between (-aspect_ratio, -1) and (aspect_ratio, 1).

direction()

glm::vec2 direction();

Returns a random direction (vector of length 1).

angle()

Angle angle();

Returns a random angle.


Updated on 2024 October 24