Commit 7b066470 authored by Shlomi Fish's avatar Shlomi Fish
Browse files

Use specialized QRandomGenerator methods.

Thanks to coates' input on D26201.
parent e95e8f01
...@@ -789,7 +789,7 @@ MoveHint DealerScene::chooseHint() ...@@ -789,7 +789,7 @@ MoveHint DealerScene::chooseHint()
else else
{ {
// Generate a random number with an exponentional distribution averaging 1/4. // Generate a random number with an exponentional distribution averaging 1/4.
qreal randomExp = qMin<qreal>( -log( 1 - qreal( QRandomGenerator::global()->generate() ) / RAND_MAX ) / 4, 1 ); qreal randomExp = qMin<qreal>( -log( 1 - QRandomGenerator::global()->generateDouble() ) / 4, 1 );
int randomIndex = randomExp * ( hintList.size() - 1 ); int randomIndex = randomExp * ( hintList.size() - 1 );
std::sort(hintList.begin(), hintList.end(), prioSort); std::sort(hintList.begin(), hintList.end(), prioSort);
......
...@@ -421,7 +421,7 @@ void MainWindow::startNew(int gameNumber) ...@@ -421,7 +421,7 @@ void MainWindow::startNew(int gameNumber)
void MainWindow::slotPickRandom() void MainWindow::slotPickRandom()
{ {
QList<KCardTheme> themes = KCardTheme::findAll(); QList<KCardTheme> themes = KCardTheme::findAll();
KCardTheme theme = themes.at( QRandomGenerator::global()->generate() % themes.size() ); KCardTheme theme = themes.at( QRandomGenerator::global()->bounded( themes.size() ) );
Settings::setCardTheme( theme.dirName() ); Settings::setCardTheme( theme.dirName() );
appearanceChanged(); appearanceChanged();
......
...@@ -402,8 +402,8 @@ void Spider::moveFullRunToLeg( KCardPile * pile ) ...@@ -402,8 +402,8 @@ void Spider::moveFullRunToLeg( KCardPile * pile )
QPointF Spider::randomPos() QPointF Spider::randomPos()
{ {
QRectF rect = sceneRect(); QRectF rect = sceneRect();
qreal x = rect.left() + qreal(QRandomGenerator::global()->generate()) / RAND_MAX * (rect.width() - deck()->cardWidth()); qreal x = rect.left() + QRandomGenerator::global()->bounded( rect.width() - deck()->cardWidth() );
qreal y = rect.top() + qreal(QRandomGenerator::global()->generate()) / RAND_MAX * (rect.height() - deck()->cardHeight()); qreal y = rect.top() + QRandomGenerator::global()->bounded( rect.height() - deck()->cardHeight() );
return QPointF( x, y ); return QPointF( x, y );
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment