File indexing completed on 2024-05-19 03:56:22
0001 /* 0002 This file is part of the KDE libraries 0003 0004 SPDX-FileCopyrightText: 1999 Matthias Kalle Dalheimer <kalle@kde.org> 0005 SPDX-FileCopyrightText: 2000 Charles Samuels <charles@kde.org> 0006 SPDX-FileCopyrightText: 2005 Joseph Wenninger <kde@jowenn.at> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #include "krandom.h" 0012 0013 #include <stdlib.h> 0014 #ifdef Q_OS_WIN 0015 #include <process.h> 0016 #else // Q_OS_WIN 0017 #include <unistd.h> 0018 #endif // Q_OS_WIN 0019 #include <stdio.h> 0020 #include <time.h> 0021 #ifndef Q_OS_WIN 0022 #include <sys/time.h> 0023 #endif // Q_OS_WIN 0024 #include <fcntl.h> 0025 0026 #include <QFile> 0027 #include <QThread> 0028 #include <QThreadStorage> 0029 0030 QString KRandom::randomString(int length) 0031 { 0032 if (length <= 0) { 0033 return QString(); 0034 } 0035 0036 QString str; 0037 str.resize(length); 0038 int i = 0; 0039 while (length--) { 0040 int r = QRandomGenerator::global()->bounded(62); 0041 r += 48; 0042 if (r > 57) { 0043 r += 7; 0044 } 0045 if (r > 90) { 0046 r += 6; 0047 } 0048 str[i++] = QLatin1Char(char(r)); 0049 // so what if I work backwards? 0050 } 0051 return str; 0052 }