6.7 KiB
[alg.rand]
26 Algorithms library [algorithms]
26.12 Specialized algorithms [alg.rand]
26.12.1 General [alg.rand.general]
The contents specified in [alg.rand] are declared in the header .
26.12.2 generate_random [alg.rand.generate]
template<class R, class G> requires [output_range](range.refinements#concept:output_range "25.4.6 Other range refinements [range.refinements]")<R, invoke_result_t<G&>> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g);
Effects:
-
Calls g.generate_random(std::forward(r)) if this expression is well-formed.
-
Otherwise, if R models sized_range, fills r with ranges::size(r) values of type invoke_result_t<G&> by performing an unspecified number of invocations of the form g() or g.generate_random(s), if such an expression is well-formed for a value N and an object s of type span<invoke_result_t<G&>, N>. [Note 1: Values of N can differ between invocations. â end note]
-
Otherwise, calls ranges::generate(std::forward(r), ref(g)).
Returns: ranges::end(r).
Remarks: The effects of generate_random(r, g) shall be equivalent toranges::generate(std::forward(r), ref(g)).
[Note 2:
This implies that g.generate_random(a) fills a with the same values as produced by invocation of g().
â end note]
template<class G, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S> requires [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> constexpr O ranges::generate_random(O first, S last, G&& g);
Effects: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g);
template<class R, class G, class D> requires [output_range](range.refinements#concept:output_range "25.4.6 Other range refinements [range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> && is_arithmetic_v<invoke_result_t<D&, G&>> constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d);
Effects:
-
Calls d.generate_random(std::forward(r), g) if this expression is well-formed.
-
Otherwise, if R models sized_range, fills r with ranges::size(r) values of type invoke_result_t<D&, G&> by performing an unspecified number of invocations of the form invoke(d, g) or d.generate_random(s, g), if such an expression is well-formed for a value N and an object s of type span<invoke_result_t<D&, G&>, N>. [Note 3: Values of N can differ between invocations. â end note]
-
Otherwise, callsranges::generate(std::forward(r), [&d, &g] { return invoke(d, g); });
Returns: ranges::end(r).
Remarks: The effects of generate_random(r, g, d) shall be equivalent toranges::generate(std::forward(r), [&d, &g] { return invoke(d, g); })
[Note 4:
This implies that d.generate_random(a, g) fills a with the values with the same random distribution as produced by invocation of invoke(d, g).
â end note]
template<class G, class D, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S> requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> && is_arithmetic_v<invoke_result_t<D&, G&>> constexpr O ranges::generate_random(O first, S last, G&& g, D&& d);
Effects: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g, d);