diff --git a/src/analysis/processing/qgsalgorithmnormalraster.cpp b/src/analysis/processing/qgsalgorithmnormalraster.cpp index 206b0fa6e4f..df92995535b 100644 --- a/src/analysis/processing/qgsalgorithmnormalraster.cpp +++ b/src/analysis/processing/qgsalgorithmnormalraster.cpp @@ -113,13 +113,16 @@ bool QgsNormalRasterAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, mMean = parameterAsDouble( parameters, QStringLiteral( "MEAN" ), context ); mStdev = parameterAsDouble( parameters, QStringLiteral( "STDEV" ), context ); - mNormalDoubleDistribution = std::normal_distribution( mMean, mStdev ); - return true; } QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) { + std::random_device rd {}; + std::mt19937 mersenneTwister{rd()}; + + std::normal_distribution normalDoubleDistribution = std::normal_distribution( mMean, mStdev ); + const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context ); QFileInfo fi( outputFile ); const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() ); @@ -157,7 +160,7 @@ QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶m std::vector float32Row( cols ); for ( int col = 0; col < cols; col++ ) { - float32Row[col] = static_cast( mNormalDoubleDistribution( mRandomDevice ) ); + float32Row[col] = static_cast( normalDoubleDistribution( mersenneTwister ) ); } block.setData( QByteArray( reinterpret_cast( float32Row.data() ), QgsRasterBlock::typeSize( Qgis::Float32 ) * cols ) ); break; @@ -167,7 +170,7 @@ QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶m std::vector float64Row( cols ); for ( int col = 0; col < cols; col++ ) { - float64Row[col] = mNormalDoubleDistribution( mRandomDevice ); + float64Row[col] = normalDoubleDistribution( mersenneTwister ); } block.setData( QByteArray( reinterpret_cast( float64Row.data() ), QgsRasterBlock::typeSize( Qgis::Float64 ) * cols ) ); break; diff --git a/src/analysis/processing/qgsalgorithmnormalraster.h b/src/analysis/processing/qgsalgorithmnormalraster.h index 01236ff6fd6..a1dadcacb6e 100644 --- a/src/analysis/processing/qgsalgorithmnormalraster.h +++ b/src/analysis/processing/qgsalgorithmnormalraster.h @@ -56,13 +56,9 @@ class QgsNormalRasterAlgorithm : public QgsProcessingAlgorithm double mPixelSize; Qgis::DataType mRasterDataType; int mTypeId; - std::random_device mRandomDevice; - std::mt19937 mMersenneTwister; double mMean; double mStdev; - - std::normal_distribution mNormalDoubleDistribution; }; ///@endcond PRIVATE