Skip to content
Snippets Groups Projects
Commit 7a5c6703 authored by Philip Trettner's avatar Philip Trettner
Browse files

added tg::shuffle

parent ea2785c9
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,5 @@
#include <typed-geometry/functions/random/gaussian.hh>
#include <typed-geometry/functions/random/random.hh>
#include <typed-geometry/functions/random/random_choice.hh>
#include <typed-geometry/functions/random/shuffle.hh>
#include <typed-geometry/functions/random/uniform.hh>
#pragma once
#include <typed-geometry/types/span.hh>
namespace tg
{
template <class Rng, class T>
constexpr void shuffle(Rng& rng, span<T> range)
{
for (size_t i = 1; i < range.size(); ++i)
{
auto j = rng() % (i + 1);
if (i != j)
detail::swap(range[i], range[j]);
}
}
template <class Rng, class Range>
constexpr void shuffle(Rng& rng, Range& range)
{
shuffle(rng, tg::span(range));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment