You did not tell us whether you want to randomly iterate over the entire array, or if you only need some elements.
I guess the first case. You will need additional storage for accounting, and you still need time to shuffle. Therefore, create a permutation and save its memory so that you can shuffle it as you wish. C ++ 11:
#include <algorithm>
#include <random>
#include <numeric>
struct permutation
{
permutation(size_t n)
: perm(n), g(std::random_device())
{
std::iota(perm.begin(), perm.end(), size_t(0));
}
void shuffle() { std::shuffle(perm.begin(), perm.end(), g); }
size_t operator[](size_t n) const { return perm[n]; }
private:
std::vector<size_t> perm;
std::mt19937 g;
};
Using:
std::vector<huge_t> v;
...
permutation sigma(v.size());
sigma.shuffle();
const huge_t& x = v[sigma[0]];
...
sigma.shuffle();
const huge_t& y = v[sigma[0]];
++ 03 std::random_shuffle, , .