I need a fast way to generate 256 rows, each with 256 random bytes and no duplicates.
The lookup tables are generated in such way the element in the first table points to the element from the 2nd that points to the one in the 1st table, but that's not the point.
This is what I have so far (kinda slow, especially the while (random_int >= (int)unused.size()) part):
unsigned char lookup_table[256 * 256];
unsigned char lookup_table_inverted[256 * 256];
std::vector<unsigned char> unused;
std::mt19937_64 rng(seed);
std::uniform_int_distribution<int> dist(0, 255);
int random_int;
for (int i = 0; i < 256; ++i)
{
for (int j = 0; j < 256; ++j)
{
unused.push_back((unsigned char)j);
}
for (int j = 0; j < 256; ++j)
{
random_int = dist(rng);
while (random_int >= (int)unused.size())
{
random_int = dist(rng);
}
lookup_table[(i * 256) + j] = unused[random_int];
lookup_table_inverted[(i * 256) + unused[random_int]] = (unsigned char)j;
unused.erase(unused.begin() + random_int);
}
}
Aucun commentaire:
Enregistrer un commentaire