random key generator c++ all unique characters

#include <iostream>
#include <algorithm>
#include <random>
#include <chrono>

int main() {
    const int length = 10; // Change the length as needed
    const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // Add/remove characters as needed
    const int charsetSize = sizeof(charset) - 1;

    std::default_random_engine rng(std::chrono::system_clock::now().time_since_epoch().count());
    std::uniform_int_distribution<int> distribution(0, charsetSize - 1);

    char key[length];
    for (int i = 0; i < length; ++i) {
        key[i] = charset[distribution(rng)];
        for (int j = 0; j < i; ++j) {
            if (key[i] == key[j]) {
                --i;
                break;
            }
        }
    }

    std::cout << "Random Key: " << key << std::endl;

    return 0;
}