diff --git a/engine/util/rng.hpp b/engine/util/rng.hpp index 305b128864f..eef9630174c 100644 --- a/engine/util/rng.hpp +++ b/engine/util/rng.hpp @@ -115,17 +115,21 @@ struct basic_rng_t return range( T{}, max ); } - // Uniform distribution in the range [first element..last element] - template () ) )>> - U& range( T& container ) + // Uniform distribution in the range [first iterator..last iterator) + template < + typename T, + typename std::enable_if_t< + std::is_base_of_v::iterator_category>, int> = 0> + T range( T first, T last ) { - return container[ range( container.size() ) ]; + return first + range( std::distance( first, last ) ); } + // Uniform distribution across [container.front()..container.back()] template () ) )>> - const U& range( const T& container ) + U& range( T& container ) { - return container[ range( container.size() ) ]; + return *range( container.begin(), container.end() ); } /// Gaussian Distribution, Non-truncated