KRandom Namespace

Helper to create random data. More...

Header: #include <KRandom>
CMake: find_package(KF6 REQUIRED COMPONENTS CoreAddons)
target_link_libraries(mytarget PRIVATE KF6::CoreAddons)

Functions

QString randomString(int length)
(since 5.73) void shuffle(T &container)
(since 5.73) void shuffle(T &container, QRandomGenerator *generator)

Detailed Description

This namespace provides methods which generate random data. KRandom is not recommended for serious random-number generation needs, like cryptography.

Function Documentation

QString KRandom::randomString(int length)

Generates a random string. It operates in the range [A-Za-z0-9] length Generate a string of this length. Returns the random string

[since 5.73] template <typename T> void KRandom::shuffle(T &container)

Reorders the elements of the given container randomly.

The container needs to implement size() and T &operator[]

This function was introduced in 5.73.

[since 5.73] template <typename T> void KRandom::shuffle(T &container, QRandomGenerator *generator)

Reorders the elements of the given container randomly using the given random number generator.

The container needs to implement size() and T &operator[]

This function was introduced in 5.73.