@zach 's way will work great. If you want a unique set of 5 from a sequence each time, you could also do something like this:
std::vector<int> getRandomInts(int rangeStart,
// These asserts are a quick replacement for errors or exceptions.
assert(rangeEnd > rangeStart);
assert(std::abs(rangeEnd - rangeStart) >= numToSample);
// Create an empty vector large enough to hold the range of numbers.
std::vector<int> numbers(std::abs(rangeEnd - rangeStart));
// Fill the vector with a sequence of numbers (this is a cool but a for-loop works too).
std::iota(numbers.begin(), numbers.end(), rangeStart);
// Shuffle the numbers.
// Throw away all but the number you want.
// Return the ones you didn't throw away.
To use it, you could do something like this.
// Select 5 numbers without replacement from [0, 30].
std::vector<int> ints = getRandomInts(0, 31, 5);
std::cout << ofToString(ints) << std::endl;
The main difference between this method and the one above is that each set of 5 numbers will not have repeats, but subsequent sets of 5 could have repeats. If you want to exhaustively select each of the numbers in the sequence from [0, 30] before repeats are allowed use @zach’s method or set
numToSample = std::abs(rangeEnd - rangeStart);