xtd 0.2.0
Loading...
Searching...
No Matches
random3.cpp

Shows how to use xtd::random::next method.

#include <xtd/console>
#include <xtd/random>
using namespace xtd;
using namespace xtd::collections::generic;
auto main() -> int {
auto rnd = xtd::random {};
auto male_pet_names = list {"Rufus", "Bear", "Dakota", "Fido", "Vanya", "Samuel", "Koani", "Volodya", "Prince", "Yiska"};
auto female_pet_names = list {"Maggie", "Penny", "Saya", "Princess", "Abby", "Laila", "Sadie", "Olivia", "Starlight", "Talla"};
// Generate random indexes for pet names.
auto male_index = rnd.next(male_pet_names.size());
auto female_index = rnd.next(female_pet_names.size());
// Display the result.
console::write_line("Suggested pet name of the day: ");
console::write_line(" For a male: {0}", male_pet_names[male_index]);
console::write_line(" For a female: {0}", female_pet_names[female_index]);
}
// This code can produce the following output :
//
// Suggested pet name of the day:
// For a male: Prince
// For a female: Talla
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.h:40
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10