Random
Pick random numbers, points, directions, etc.
Summary
Functions
| Name | |
|---|---|
| float | number() Returns a random number between 0 and 1. |
| float | number(float max)Returns a random number between 0 and max. |
| float | number(float min, float max)Returns a random number between min and max. |
| int | integer(int max)Returns a random integer between 0 (included) and max (excluded). |
| int | integer(int min, int max)Returns a random integer between min (included) and max (excluded). |
| size_t | size_type(size_t max)Returns a random size_t between 0 (included) and max (excluded). |
| size_t | size_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::vec2 | point(const [p6::Context](/reference/Types/context) & ctx)Returns a point inside the main canvas of the context. |
| glm::vec2 | point(const [p6::Canvas](/reference/Types/canvas) & canvas)Returns a point inside the given canvas. |
| glm::vec2 | point() Returns a random point in a square between (-1, -1) and (1, 1). |
| glm::vec2 | point(glm::vec2 min, glm::vec2 max)Returns a random point in a rectangle between min and max. |
| glm::vec2 | point(float aspect_ratio)Returns a random point in a rectangle between (-aspect_ratio, -1) and (aspect_ratio, 1). |
| glm::vec2 | direction() Returns a random direction (vector of length 1). |
| Angle | angle() Returns a random angle. |
Functions
number()
floatnumber();
Returns a random number between 0 and 1.
number()
floatnumber(floatmax);
Returns a random number between 0 and max.
Throws a std::invalid_argument exception if max < 0.
number()
floatnumber(floatmin,floatmax);
Returns a random number between min and max.
Throws a std::invalid_argument exception if min > max.
integer()
intinteger(intmax);
Returns a random integer between 0 (included) and max (excluded).
Throws a std::invalid_argument exception if max <= 0.
integer()
intinteger(intmin,intmax);
Returns a random integer between min (included) and max (excluded).
Throws a std::invalid_argument exception if min >= max.
size_type()
size_tsize_type(size_tmax);
Returns a random size_t between 0 (included) and max (excluded).
size_type()
size_tsize_type(size_tmin,size_tmax);
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::vec2point(const [p6::Context](/reference/Types/context) &ctx);
Returns a point inside the main canvas of the context.
point()
glm::vec2point(const [p6::Canvas](/reference/Types/canvas) &canvas);
Returns a point inside the given canvas.
point()
glm::vec2point();
Returns a random point in a square between (-1, -1) and (1, 1).
point()
glm::vec2point(glm::vec2min,glm::vec2max);
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::vec2point(floataspect_ratio);
Returns a random point in a rectangle between (-aspect_ratio, -1) and (aspect_ratio, 1).
direction()
glm::vec2direction();
Returns a random direction (vector of length 1).
angle()
Angleangle();
Returns a random angle.
Updated on 2024 October 24