1/*
2 This file is part of the KDE libraries
3
4 SPDX-FileCopyrightText: 1999 Matthias Kalle Dalheimer <kalle@kde.org>
5 SPDX-FileCopyrightText: 2000 Charles Samuels <charles@kde.org>
6 SPDX-FileCopyrightText: 2005 Joseph Wenninger <kde@jowenn.at>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#include "krandom.h"
12
13QString KRandom::randomString(int length)
14{
15 if (length <= 0) {
16 return QString();
17 }
18
19 QString str;
20 str.resize(size: length);
21 int i = 0;
22 while (length--) {
23 int r = QRandomGenerator::global()->bounded(highest: 62);
24 r += 48;
25 if (r > 57) {
26 r += 7;
27 }
28 if (r > 90) {
29 r += 6;
30 }
31 str[i++] = QLatin1Char(char(r));
32 // so what if I work backwards?
33 }
34 return str;
35}
36

source code of kcoreaddons/src/lib/randomness/krandom.cpp