UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Geometry::FModuloIteration Struct Reference

#include <IteratorUtil.h>

Public Member Functions

 FModuloIteration (uint32 MaxIndexIn, uint32 StartIndexIn=0, uint64 ModuloPrimeIn=3208642561)
 
bool GetNextIndex (uint32 &NextIndexOut)
 
bool GetNextIndex (int32 &NextIndexOut)
 

Public Attributes

uint64 MaxIndex = 0
 
uint64 ModuloPrime = 4294967311ull
 
uint64 CurIndex = 0
 
uint64 StartIndex = 0
 
uint64 Count = 0
 
uint64 ModuloNum = 1
 

Detailed Description

FModuloIteration is used to iterate over a range of indices [0,N) using modulo-arithmetic. The iteration proceeds as NextValue = (CurValue + ModuloValue) % N. As long as the ModuloValue is a prime number > N/2, then every integer in the sequence 0...N-1 will appear exactly once before 0 re-appears (and in fact any index in the range can be used as the starting value).

FModuloIteration computes in 64-bit with (by default) a large enough prime that will work for any 32-bit unsigned integer. If 64-bit iterations are needed, some larger primes can be found here: https://en.wikipedia.org/wiki/P%C3%A9pin%27s_test

(The prime does not strictly need to be > N/2, any prime will work as long as it is not a divisor of N. And it doesn't even need to be a prime number, just a co-prime of N, ie GCD(N, ModuloValue) = 1. It is possible to check GCD relatively quickly to search for valid constants, for example if many values were needed to use as seeds/etc)

Usage:

FModuloIteration Iter(N); uint32 Index; while (Iter.GetNextIndex(Index)) { ... }

Constructor & Destructor Documentation

◆ FModuloIteration()

UE::Geometry::FModuloIteration::FModuloIteration ( uint32  MaxIndexIn,
uint32  StartIndexIn = 0,
uint64  ModuloPrimeIn = 3208642561 
)
inline

Member Function Documentation

◆ GetNextIndex() [1/2]

bool UE::Geometry::FModuloIteration::GetNextIndex ( int32 NextIndexOut)
inline

◆ GetNextIndex() [2/2]

bool UE::Geometry::FModuloIteration::GetNextIndex ( uint32 NextIndexOut)
inline

Member Data Documentation

◆ Count

uint64 UE::Geometry::FModuloIteration::Count = 0

◆ CurIndex

uint64 UE::Geometry::FModuloIteration::CurIndex = 0

◆ MaxIndex

uint64 UE::Geometry::FModuloIteration::MaxIndex = 0

◆ ModuloNum

uint64 UE::Geometry::FModuloIteration::ModuloNum = 1

◆ ModuloPrime

uint64 UE::Geometry::FModuloIteration::ModuloPrime = 4294967311ull

◆ StartIndex

uint64 UE::Geometry::FModuloIteration::StartIndex = 0

The documentation for this struct was generated from the following file: