Skip to content

Commit

Permalink
STYLE: Localize variables and use const
Browse files Browse the repository at this point in the history
Minor refactoring to localize variables to minimum scope
Minor refactoring to make non-changing varialbes constant
  • Loading branch information
hjmjohnson committed Apr 7, 2024
1 parent dc65864 commit d17f47d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Modules/Core/TestKernel/include/itkRandomImageSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ RandomImageSource<TOutputImage>::DynamicThreadedGenerateData(const OutputImageRe
using scalarType = typename TOutputImage::PixelType;
typename TOutputImage::Pointer image = this->GetOutput(0);

ImageRegionIterator<TOutputImage> it(image, outputRegionForThread);

TotalProgressReporter progress(this, image->GetRequestedRegion().GetNumberOfPixels());

IndexValueType indSeed = outputRegionForThread.GetIndex(0);
Expand All @@ -231,17 +229,15 @@ RandomImageSource<TOutputImage>::DynamicThreadedGenerateData(const OutputImageRe

// Random number seed
unsigned int sample_seed = 12345 + indSeed;
double u;
double rnd;

auto dMin = static_cast<double>(m_Min);
auto dMax = static_cast<double>(m_Max);
const auto dMin = static_cast<double>(m_Min);
const auto dMax = static_cast<double>(m_Max);

for (; !it.IsAtEnd(); ++it)
for (ImageRegionIterator<TOutputImage> it(image, outputRegionForThread); !it.IsAtEnd(); ++it)
{
sample_seed = (sample_seed * 16807) % 2147483647L;
u = static_cast<double>(sample_seed) / 2147483711UL;
rnd = (1.0 - u) * dMin + u * dMax;
const double u = static_cast<double>(sample_seed) / 2147483711UL;
const double rnd = (1.0 - u) * dMin + u * dMax;

it.Set((scalarType)rnd);
progress.CompletedPixel();
Expand Down

0 comments on commit d17f47d

Please sign in to comment.