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()
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