From 2f452500a59e559da19fe7fde2e224da109165d5 Mon Sep 17 00:00:00 2001 From: Jonathan Guinet <jonathan.guinet@c-s.fr> Date: Thu, 5 Jan 2012 17:02:10 +0100 Subject: [PATCH] ENH: rand() have been replaced by MersenneTwister GetUniformVariate() method. --- Applications/Classification/otbKMeansClassification.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Applications/Classification/otbKMeansClassification.cxx b/Applications/Classification/otbKMeansClassification.cxx index 930cdc5d52..abe4af7f8f 100644 --- a/Applications/Classification/otbKMeansClassification.cxx +++ b/Applications/Classification/otbKMeansClassification.cxx @@ -19,6 +19,7 @@ #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" +#include "itkMersenneTwisterRandomVariateGenerator.h" #include "otbVectorImage.h" #include "otbImage.h" #include "itkEuclideanDistance.h" @@ -39,6 +40,7 @@ #include "otbWrapperTypes.h" + namespace otb { @@ -346,7 +348,7 @@ private: SampleType sample; //first sample - + itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randGen=itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance(); if (maskFlag) { while (!it.IsAtEnd() && !m_MaskIt .IsAtEnd() && (m_MaskIt.Get() <= 0)) @@ -409,9 +411,7 @@ private: { for (unsigned int compIndex = 0; compIndex < sampleSize; ++compIndex) { - initialMeans[compIndex + classIndex * sampleSize] = min[compIndex] + (max[compIndex] - min[compIndex]) * rand() - / (RAND_MAX + 1.0); - + initialMeans[compIndex + classIndex * sampleSize] = min[compIndex] + (max[compIndex] - min[compIndex]) * randGen->GetUniformVariate(0.0, 1.0); } } otbAppLogINFO(<<totalSamples <<" samples will be used as estimator input."<<std::endl); -- GitLab