From cb8535cdbcc13bc47000bd5a8c273ae697d1e0c1 Mon Sep 17 00:00:00 2001 From: khizmax Date: Thu, 14 May 2015 00:44:42 +0300 Subject: [PATCH] random_shuffle_permutation refactoring --- cds/opt/permutation.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cds/opt/permutation.h b/cds/opt/permutation.h index dbf138c7..861254a9 100644 --- a/cds/opt/permutation.h +++ b/cds/opt/permutation.h @@ -6,6 +6,7 @@ #include // rand, srand #include #include // std::shuffle +#include // std::iota #include @@ -203,20 +204,16 @@ namespace cds { namespace opt { integer_type * m_pCur; integer_type * m_pFirst; integer_type * m_pLast; - - random_generator m_RandomGenerator; //@endcond public: /// Initializes the generator of arbitrary length \p nLength random_shuffle_permutation( size_t nLength ) : m_pCur( nullptr ) - , m_RandomGenerator( random_device()() ) { m_pFirst = new integer_type[nLength]; m_pLast = m_pFirst + nLength; - for ( integer_type i = 0; i < static_cast(nLength); ++i ) - m_pFirst[i] = i; + std::iota(m_pFirst, m_pLast, integer_type{0} ); reset(); } @@ -240,7 +237,7 @@ namespace cds { namespace opt { /// Resets the generator to produce new sequence void reset() { - std::shuffle( m_pFirst, m_pLast, m_RandomGenerator ); + std::shuffle( m_pFirst, m_pLast, random_generator{ random_device{}() }); m_pCur = m_pFirst; } }; -- 2.34.1