OpenShot Library | libopenshot 0.5.0
Loading...
Searching...
No Matches
IdGenerator.h
Go to the documentation of this file.
1/*
2 * @file
3 * @brief Header file for generating random identifier strings
4 */
5
6// Copyright (c) 2008-2025 OpenShot Studios, LLC
7//
8// SPDX-License-Identifier: LGPL-3.0-or-later
9
10#ifndef OPENSHOT_ID_GENERATOR_H
11#define OPENSHOT_ID_GENERATOR_H
12
13#include <random>
14#include <string>
15
16namespace openshot {
17
19 public:
20 static inline std::string Generate(int length = 8) {
21 static const char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
22 std::random_device rd;
23 std::mt19937 gen(rd());
24 std::uniform_int_distribution<> dist(0, static_cast<int>(sizeof(charset) - 2));
25
26 std::string result;
27 result.reserve(length);
28 for (int i = 0; i < length; ++i)
29 result += charset[dist(gen)];
30 return result;
31}
32};
33
34} // namespace openshot
35
36#endif // OPENSHOT_ID_GENERATOR_H
static std::string Generate(int length=8)
Definition IdGenerator.h:20
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29