Skip to content

Use QRandomGenerator instead of deprecated qrand()

Michael Genda requested to merge gikari/krita:work/gikari/qt_515_random into master

qrand and qsrand are deprecated and will be removed from Qt 6, so it is desirable to replace them. According to Qt Documentation, they should be replaced with QRandomGenerator.

QRandomGenerator::global() is automatically seeded with system RNG, so it must not be reseeded:

QRandomGenerator::global(), like all generators created by QRandomGenerator::securelySeeded(), is always seeded from QRandomGenerator::system(), so it's not possible to make it produce identical sequences.

Test Plan

  1. Changed Unit-tests must pass
  2. Krita functions that use random values should work.

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
  • Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.

Merge request reports