58 explicit random(std::random_device& random_device);
72 const std::default_random_engine&
generator() const noexcept;
84 template<class value_t>
94 template<
class value_t>
101 template<
class value_t>
103 for (
auto& item : destination)
104 item = choices[
next(choices.size())];
112 template<
class value_t>
128 template<
class value_t>
129 value_t
next(value_t max_value)
const {
130 return static_cast<value_t
>(
next(value_t {}, max_value));
129 value_t
next(value_t max_value)
const {
…}
148 template<
class value_t>
149 value_t
next(value_t min_value, value_t max_value)
const {
151 if (min_value == max_value)
return min_value;
152 return min_value +
static_cast<value_t
>(
math::round(
sample() * (max_value - 1 - min_value)));
149 value_t
next(value_t min_value, value_t max_value)
const {
…}
156 template<xtd::
boolean>
160 double next(
double max_value)
const;
161 float next(
float max_value)
const;
164 double next(
double min_value,
double max_value)
const;
165 float next(
float min_value,
float max_value)
const;
185 template<
class value_t>
187 for (
auto index = 0_z; index < buffer.
size(); ++index)
194 template<
class value_t>
224 template<
class value_t>
226 for (
auto index = 0_z; index < values.
length() - 1; ++index)
227 std::swap(values[index], values[
next(index, values.
length())]);
231 template<
class collection_t>
245 mutable std::default_random_engine generator_;
Contains xtd::argument_null_exception exception.
Contains xtd::argument_out_of_range_exception exception.
Contains xtd::array class.
Contains xtd::box_integer class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
static constexpr type_t max_value
Represents the largest possible value of type_t. This field is constant.
Definition box_integer.hpp:67
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
static decimal round(decimal value)
Rounds a double-precision floating-point value to the nearest integral value.
object()=default
Create a new instance of the ultimate base class object.
value_t next(value_t max_value) const
Returns a nonnegative random number less than the specified maximum.
Definition random.hpp:129
virtual int32 next(int32 min_value, int32 max_value) const
Returns a random number within a specified range.
random(uint32 seed)
Initializes a new instance of the random class, using a specified seed value.
void shuffle(collection_t &values) const
Performs an in-place shuffle of an array.
Definition random.hpp:232
virtual int32 next(int32 max_value) const
Returns a nonnegative random number less than the specified maximum.
void get_items(const xtd::read_only_span< value_t > &choices, xtd::span< value_t > &destination)
Fills the elements of a specified span with items chosen at random from the provided set of choices.
Definition random.hpp:102
virtual double next_double() const
Returns a random number between 0.0 and 1.0.
virtual single next_single() const
Returns a random number between 0.0 and 1.0.
xtd::array< value_t > get_items(const xtd::read_only_span< value_t > &choices, xtd::size length)
Creates an array populated with items chosen at random from the provided set of choices.
Definition random.hpp:85
virtual int64 next_int64(int64 min_value, int64 max_value) const
Returns a random number within a specified range.
random(std::random_device &random_device)
Initializes a new instance of the random class, using a specified random device value.
virtual int32 next() const
Returns a nonnegative random number.
const std::default_random_engine & generator() const noexcept
Gets the underlying generator.
xtd::array< value_t > get_items(const xtd::array< value_t > &choices, xtd::size length)
Creates an array populated with items chosen at random from the provided set of choices.
Definition random.hpp:95
virtual int64 next_int64(int64 max_value) const
Returns a nonnegative random number less than the specified maximum.
value_t next(value_t min_value, value_t max_value) const
Returns a random number within a specified range.
Definition random.hpp:149
value_t next() const
Returns a nonnegative random number.
Definition random.hpp:113
virtual int64 next_int64() const
Returns a nonnegative random number.
void next_values(xtd::span< value_t > &buffer) const
Fills the elements of a specified xtd::span of bytes with random numbers.
Definition random.hpp:186
virtual void next_bytes(xtd::array< xtd::byte > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
void next_values(xtd::array< value_t > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
Definition random.hpp:195
random()
Initializes a new instance of the random class, using a default generated seed value.
virtual double sample() const
Returns a random number between 0.0 and 1.0.
virtual void next_bytes(xtd::span< xtd::byte > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
void shuffle(xtd::span< value_t > &values) const
Performs an in-place shuffle of a span.
Definition random.hpp:225
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:58
constexpr size_type length() const noexcept
Returns the length of the current span.
Definition span.hpp:253
constexpr size_type size() const noexcept
Returns the number of elements.
Definition span.hpp:271
Contains core_export_ keyword.
Contains xtd::environment class.
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
bool boolean
Represents a boolean.
Definition boolean.hpp:23
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
float single
Represents a single-precision floating-point number.
Definition single.hpp:23
Contains xtd::math class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr read_only_span(const element_type(&array)[len]) noexcept
Creates an xtd::read_only_span with specified native array.
Definition read_only_span.hpp:112
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
Contains xtd numeric literals.
Contains xtd::object class.
Contains xtd::optional type.
Contains xtd::span class.