Distinct generator for discrete uniform functions.
More...
|
| | distinct (Func func, Args... args) |
| | Generates a distinct generator of a discrete uniform function.
|
| auto | gen () |
| | Generates a distinct value.
|
| auto | gen_list (int size) |
| | Generates a list of several distinct values.
|
| bool | empty () |
| | Checks if there is nothing left to generate.
|
| auto | gen_all () |
| | Generates all distinct values left to generate.
|
template<typename Func, typename... Args>
struct tgen::distinct< Func, Args >
Distinct generator for discrete uniform functions.
Examples
[&]() {
return x * x;
T next(T right)
Returns a random number up to value.
uint64_t gen_prime(uint64_t left, uint64_t right)
Generates a random prime in given range.
std::string gen_parenthesis(int size)
Generates a random valid parenthesis sequence.
Distinct generator for discrete uniform functions.
auto gen_list(int size)
Generates a list of several distinct values.
auto gen_all()
Generates all distinct values left to generate.
auto distinct(Args &&...args) const
Creates distinct generator for current generator.
Definition at line 235 of file tgen.h.
◆ distinct()
template<typename Func, typename... Args>
Generates a distinct generator of a discrete uniform function.
- Template Parameters
-
| Func | Automatically set to the function type. |
- Parameters
-
| func | The function. |
| args | Arguments for the function. |
- Precondition
- Return type of func must have less-than operator overload (operator<).
The function must be uniform on its image (every value in the function's image must have the same probability of being returned).
Examples
[&](int l, int r) {
return x * x;
}, 1, 1e2);
Definition at line 241 of file tgen.h.
◆ empty()
template<typename Func, typename... Args>
Checks if there is nothing left to generate.
- Returns
- If there is probably (with probability at least 1 - 10^(-18)) no value that has not been generated yet.
Complexity
The same as a call to distinct::gen.
Examples
while (!g.empty()) std::cout << g.gen() << std::endl;
Definition at line 299 of file tgen.h.
◆ gen()
template<typename Func, typename... Args>
Generates a distinct value.
- Template Parameters
-
| Func | Automatically set to the function type. |
- Returns
- A new value that has not been generated before, uniformly at random.
- Exceptions
-
| std::runtime_error | if there are probably (with probability at least 1 - 10^(-18)) no more distinct values to generate. |
Complexity
O(T * log k + log^2 k) amortized expected, if the function runs in O(T) time and k distinct values have been generated.
Reference:
Examples
for (int i = 0; i < 10; ++i)
std::cout << g.gen() << std::endl;
for (int i = 0; i < 10; ++i)
std::cout << g.gen() << std::endl;
Definition at line 276 of file tgen.h.
◆ gen_all()
template<typename Func, typename... Args>
Generates all distinct values left to generate.
- Returns
- A uniformly random tgen::list::value with all distinct values from the function with the given arguments that have not been generated yet.
Complexity
The same as calling distinct::gen until there are no more distinct values.
Examples
Definition at line 302 of file tgen.h.
◆ gen_list()
template<typename Func, typename... Args>
Generates a list of several distinct values.
- Parameters
-
| size | Size of the list to be generated. |
- Returns
- A uniformly random tgen::list::value with size distinct values from the function with the given arguments.
- Exceptions
-
| std::runtime_error | if there are not enough values to generate. |
Complexity
The same as size calls to distinct::gen.
Examples
Definition at line 288 of file tgen.h.
The documentation for this struct was generated from the following files:
- /home/runner/work/tgen/tgen/single_include/tgen.h
- base.dox