File indexing completed on 2024-12-08 03:39:07

0001 /*
0002     This file is part of the KDE libraries
0003 
0004     SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #include <QList>
0010 #include <QString>
0011 
0012 #include "krandom.h"
0013 #include "krandomsequence.h"
0014 
0015 #include <stdio.h>
0016 
0017 int main(/*int argc, char *argv[]*/)
0018 {
0019     long seed;
0020     KRandomSequence seq;
0021 
0022     seed = 2;
0023     seq.setSeed(seed);
0024     printf("Seed = %4ld :", seed);
0025     for (int i = 0; i < 20; i++) {
0026         printf("%3ld ", seq.getLong(100));
0027     }
0028     printf("\n");
0029 
0030     seed = 0;
0031     seq.setSeed(seed);
0032     printf("Seed = %4ld :", seed);
0033     for (int i = 0; i < 20; i++) {
0034         printf("%3ld ", seq.getLong(100));
0035     }
0036     printf("\n");
0037 
0038     seed = 0;
0039     seq.setSeed(seed);
0040     printf("Seed = %4ld :", seed);
0041     for (int i = 0; i < 20; i++) {
0042         printf("%3ld ", seq.getLong(100));
0043     }
0044     printf("\n");
0045 
0046     seed = 2;
0047     seq.setSeed(seed);
0048     printf("Seed = %4ld :", seed);
0049     for (int i = 0; i < 20; i++) {
0050         printf("%3ld ", seq.getLong(100));
0051     }
0052     printf("\n");
0053 
0054     seq.setSeed(KRandom::random());
0055 
0056     QStringList list{
0057         QLatin1String("A"),
0058         QLatin1String("B"),
0059         QLatin1String("C"),
0060         QLatin1String("D"),
0061         QLatin1String("E"),
0062         QLatin1String("F"),
0063         QLatin1String("G"),
0064     };
0065 
0066     auto printList = [&list]() {
0067         for (const QString &str : std::as_const(list)) {
0068             printf("%s", str.toLatin1().data());
0069         }
0070         printf("\n");
0071     };
0072 
0073     printList();
0074 
0075     seq.randomize(list);
0076     printList();
0077 
0078     seq.randomize(list);
0079     printList();
0080 
0081     seq.randomize(list);
0082     printList();
0083 }