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
13#include <stdlib.h>
14#ifdef Q_OS_WIN
15#include <process.h>
16#else // Q_OS_WIN
17#include <unistd.h>
18#endif // Q_OS_WIN
19#include <stdio.h>
20#include <time.h>
21#ifndef Q_OS_WIN
22#include <sys/time.h>
23#endif // Q_OS_WIN
24#include <fcntl.h>
25
26#include <QFile>
27#include <QThread>
28#include <QThreadStorage>
29
30QString KRandom::randomString(int length)
31{
32 if (length <= 0) {
33 return QString();
34 }
35
36 QString str;
37 str.resize(size: length);
38 int i = 0;
39 while (length--) {
40 int r = QRandomGenerator::global()->bounded(highest: 62);
41 r += 48;
42 if (r > 57) {
43 r += 7;
44 }
45 if (r > 90) {
46 r += 6;
47 }
48 str[i++] = QLatin1Char(char(r));
49 // so what if I work backwards?
50 }
51 return str;
52}
53

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