tgen
Loading...
Searching...
No Matches
Generator Value Operations

Operations for tgen generator values. More...

Collaboration diagram for Generator Value Operations:

Functions

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
void tgen::shuffle (Inst &inst)
 Shuffles a list value.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst tgen::shuffled (const Inst &inst)
 Shuffles a list value.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::pick (const Inst &inst)
 Choses a random element from the list value.
template<typename Inst, typename T, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::pick_by_distribution (const Inst &inst, const std::vector< T > &distribution)
 Choses a random element from the list value.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value and has_subset_defined< Inst >::value, int > = 0>
Inst tgen::choose (const Inst &inst, int k)
 Chooses some values from the list value, as in a sublist of fixed length.

Detailed Description

Operations for tgen generator values.

Examples

// Shuffles and prints a value.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << tgen::shuffled(inst) << std::endl;
// Prints a random element from inst.
std::cout << tgen::pick(inst) << std::endl;
It::value_type pick(It first, It last)
Choses a random element from iterator range.
Definition tgen.h:671
auto shuffled(const C &container)
Shuffles a container.
Definition tgen.h:643
List value.
Definition tgen.h:1320

Function Documentation

◆ choose()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value and has_subset_defined< Inst >::value, int > = 0>
Inst tgen::choose ( const Inst & inst,
int k )

Chooses some values from the list value, as in a sublist of fixed length.

Template Parameters
InstList value type, deduced automatically. Must be a tgen::list::value.
Parameters
instThe original value.
kThe size of the sublist.
Returns
A uniformly random subsequence of length k.

Complexity

O(|inst|).

Examples

// Prints a subsequenec of length 2 from v.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << tgen::choose(2, inst) << std::endl;
C choose(const C &container, int k)
Chooses elements from container, as in a subsequence fixed length.
Definition tgen.h:747

Definition at line 772 of file tgen.h.

◆ pick()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::pick ( const Inst & inst)

Choses a random element from the list value.

Template Parameters
InstList value type, deduced automatically. Must be a tgen::list::value.
Parameters
instThe original value.
Returns
A uniformly random element from the value.

Complexity

O(1).

Examples

// Prints a random element from v.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << tgen::pick(inst) << std::endl;

Definition at line 691 of file tgen.h.

◆ pick_by_distribution()

template<typename Inst, typename T, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::pick_by_distribution ( const Inst & inst,
const std::vector< T > & distribution )

Choses a random element from the list value.

Template Parameters
InstList value type, deduced automatically. Must be a tgen::list::value.
Parameters
instThe value to choose from.
distributionThe probability distribution.
Returns
A uniformly random element from the value.

Complexity

O(1).

Examples

// Prints a random element from value with given odds.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << tgen::pick_by_distribution(inst, {1, 2, 3}) << std::endl;
C::value_type pick_by_distribution(const C &container, std::vector< T > distribution)
Choses a random element with given probabilities.
Definition tgen.h:699

Definition at line 731 of file tgen.h.

◆ shuffle()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
void tgen::shuffle ( Inst & inst)

Shuffles a list value.

Template Parameters
InstList value type, deduced automatically. Must be a tgen::list::value.
Parameters
instThe value to shuffle.

Complexity

O(|inst|).

Examples

// Shuffles a value.
tgen::list<int>::value inst = {3, 1, 2};
void shuffle(It first, It last)
Shuffles range inplace, for random_access_iterator.
Definition tgen.h:624

Definition at line 635 of file tgen.h.

◆ shuffled()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst tgen::shuffled ( const Inst & inst)
nodiscard

Shuffles a list value.

Template Parameters
InstList value type, deduced automatically. Must be a tgen::list::value.
Parameters
instThe original value.
Returns
The shuffled value.

Complexity

O(|inst|).

Examples

// Shuffles and prints a value.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << tgen::shuffled(inst) << std::endl;

Definition at line 663 of file tgen.h.