Control the variation and uniqueness will have to manually. I will give an example with uniqueness. You need to be careful with the cycle - all combinations will ever run out, therefore, you will need to either re-create / clear the unique
:
class UniqueRGB { public: UniqueRGB() { qsrand(QTime::currentTime().msec()); } QRgb get() { QRgb rgb; do { int r = rand() % 255; int g = rand() % 255; int b = rand() % 255; rgb = qRgba(r, g, b, 255); } while (unique.contains(rgb)); unique.insert(rgb); return rgb; } private: QSet<QRgb> unique; };
Using:
UniqueRGB uniqueRGB; for (int i = 0; i < 1000; i++) { QRgb rgb = uniqueRGB.get(); qDebug() << rgb << QColor::fromRgb(rgb); }