File: krandomsequencetest.cpp

package info (click to toggle)
kcoreaddons 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,660 kB
  • sloc: cpp: 23,523; xml: 3,284; sh: 34; makefile: 7
file content (83 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    This file is part of the KDE libraries

    SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#include <QList>
#include <QString>

#include "krandom.h"
#include "krandomsequence.h"

#include <stdio.h>

int main(/*int argc, char *argv[]*/)
{
    long seed;
    KRandomSequence seq;

    seed = 2;
    seq.setSeed(seed);
    printf("Seed = %4ld :", seed);
    for (int i = 0; i < 20; i++) {
        printf("%3ld ", seq.getLong(100));
    }
    printf("\n");

    seed = 0;
    seq.setSeed(seed);
    printf("Seed = %4ld :", seed);
    for (int i = 0; i < 20; i++) {
        printf("%3ld ", seq.getLong(100));
    }
    printf("\n");

    seed = 0;
    seq.setSeed(seed);
    printf("Seed = %4ld :", seed);
    for (int i = 0; i < 20; i++) {
        printf("%3ld ", seq.getLong(100));
    }
    printf("\n");

    seed = 2;
    seq.setSeed(seed);
    printf("Seed = %4ld :", seed);
    for (int i = 0; i < 20; i++) {
        printf("%3ld ", seq.getLong(100));
    }
    printf("\n");

    seq.setSeed(KRandom::random());

    QStringList list{
        QLatin1String("A"),
        QLatin1String("B"),
        QLatin1String("C"),
        QLatin1String("D"),
        QLatin1String("E"),
        QLatin1String("F"),
        QLatin1String("G"),
    };

    auto printList = [&list]() {
        for (const QString &str : std::as_const(list)) {
            printf("%s", str.toLatin1().data());
        }
        printf("\n");
    };

    printList();

    seq.randomize(list);
    printList();

    seq.randomize(list);
    printList();

    seq.randomize(list);
    printList();
}