57 explicit random(std::random_device& random_device);
71 const std::default_random_engine&
generator() const noexcept;
83 template<class value_t>
93 template<
class value_t>
100 template<
class value_t>
102 for (
auto& item : destination)
103 item = choices[
next(choices.
size())];
111 template<
class value_t>
127 template<
class value_t>
128 value_t
next(value_t max_value)
const {
129 return static_cast<value_t
>(
next(value_t {}, max_value));
147 template<
class value_t>
148 value_t
next(value_t min_value, value_t max_value)
const {
150 if (min_value == max_value)
return min_value;
151 return min_value +
static_cast<value_t
>(
math::round(
sample() * (max_value - 1 - min_value)));
155 template<xtd::
boolean>
159 double next(
double max_value)
const;
160 float next(
float max_value)
const;
163 double next(
double min_value,
double max_value)
const;
164 float next(
float min_value,
float max_value)
const;
184 template<
class value_t>
186 for (
auto index = 0_z; index < buffer.
size(); ++index)
187 buffer[index] = next<value_t>();
193 template<
class value_t>
223 template<
class value_t>
225 for (
auto index = 0_z; index < values.
length() - 1; ++index)
226 std::swap(values[index], values[
next(index, values.
length())]);
230 template<
class collection_t>
244 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
Represents a boxed integer object.
Definition box_integer.hpp:52
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.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.hpp:43
value_t next(value_t max_value) const
Returns a nonnegative random number less than the specified maximum.
Definition random.hpp:128
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:231
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:101
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:84
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:94
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:148
value_t next() const
Returns a nonnegative random number.
Definition random.hpp:112
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:185
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:194
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:224
Represents a non-owning view over a contiguous sequence of objects.
Definition read_only_span.hpp:52
constexpr size_type size() const noexcept
Returns the number of elements.
Definition read_only_span.hpp:241
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.
int32_t int32
Represents a 32-bit signed integer.
Definition int32.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
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
bool boolean
Represents a boolean.
Definition boolean.hpp:23
Contains xtd::math class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::object class.
Contains xtd::optional type.
Contains xtd::span class.