60 template< std::
size_t N >
63 static_assert(((N >= 4) && (N <= 20)),
"N template value is invalid (3 < N < 21)");
67 static const unsigned mSize = (1u << N);
70 static const unsigned mPolynomial = (N == 4) ? 0x9 :
86 (N == 20) ? 0x80534 : 0;
91 , mLfsr(1 + (rand() % (mSize- 2)))
97 std::lock_guard<std::mutex> locker(mLock);
100 if (mUsed.count() >= (mSize - 1))
107 unsigned lsb = (mLfsr & 0x1u);
111 mLfsr ^= mPolynomial;
113 }
while (mUsed.test(mLfsr) ==
true);
118 return static_cast<int>(mOffset + mLfsr);
123 std::lock_guard<std::mutex> locker(mLock);
126 if ((
id < 0) || (
id <=
static_cast<int>(mOffset)) ||
127 ((
id - mOffset) >=
static_cast<int>(mSize)))
131 if (!mUsed.test(
id - mOffset))
134 mUsed.reset(
id - mOffset);
140 std::lock_guard<std::mutex> locker(mLock);
148 const unsigned mOffset;
151 mutable std::mutex mLock;
152 std::bitset<mSize> mUsed;
Class used to generate unique numbers.
Definition: IDGenerator.h:62