7 #include "core_export.h" 52 explicit random(std::random_device& random_device);
66 std::default_random_engine
generator()
const noexcept;
78 template<
typename value_t>
80 return next(std::numeric_limits<value_t>::max());
95 template<
typename value_t>
96 value_t
next(value_t max_value)
const {
97 return next(0, max_value);
116 template<
typename value_t>
117 value_t
next(value_t min_value, value_t max_value)
const {
119 if (min_value == max_value)
return min_value;
120 return min_value +
static_cast<value_t
>(
math::round(
sample() * std::numeric_limits<value_t>::max())) % ((max_value - 1) - min_value + 1);
125 double next(
double max_value)
const;
126 float next(
float max_value)
const;
128 double next(
double min_value,
double max_value)
const;
129 float next(
float min_value,
float max_value)
const;
135 virtual void next_bytes(std::vector<xtd::byte>& buffer)
const;
146 template<
typename value_t>
155 template<
typename value_t>
158 for (
size_t index = 0; index < buffer_size; index++)
159 buffer[index] = next<value_t>(0, std::numeric_limits<value_t>::max());
172 virtual double sample()
const;
175 mutable std::default_random_engine generator_;
Contains xtd::math class.
The exception that is thrown when one of the arguments provided to a method is null.
Definition: argument_null_exception.h:20
value_t next() const
Returns a nonnegative random number.
Definition: random.h:79
Contains xtd::argument_out_of_range_exception exception.
Contains std::optional type and std::bad_optional_access exception.
random()
Initializes a new instance of the random class, using a default generated seed value.
value_t next(value_t min_value, value_t max_value) const
Returns a random number within a specified range.
Definition: random.h:117
long double decimal
Represents a decimal-precision floating-point number.
Definition: types.h:96
static decimal round(decimal value)
Rounds a double-precision floating-point value to the nearest integral value.
virtual double next_double() const
Returns a random number between 0.0 and 1.0.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
#define csf_
Provides information about the current stack frame.
Definition: current_stack_frame.h:30
virtual int32 next() const
Returns a nonnegative random number.
void next_values(value_t *buffer, size_t buffer_size) const
Fills the elements of a specified array of bytes with random numbers.
Definition: random.h:156
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition: random.h:38
std::default_random_engine generator() const noexcept
Gets the underlying generator.
Contains xtd::argument_null_exception exception.
The exception that is thrown when one of the arguments provided to a method is out of range...
Definition: argument_out_of_range_exception.h:20
Contains xtd::object class.
virtual double sample() const
Returns a random number between 0.0 and 1.0.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
virtual void next_bytes(std::vector< xtd::byte > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::environment class.
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:39
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
void next_values(std::vector< value_t > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
Definition: random.h:147
value_t next(value_t max_value) const
Returns a nonnegative random number less than the specified maximum.
Definition: random.h:96