#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
// Function to select random two non-consecutive digits from a number
std::string getRandomTwoDigits(long long number) {
std::string numStr = std::to_string(number);
if (numStr.size() < 2) {
return "Error: number must have at least 2 digits";
}
// Generate two distinct random indices
int i = std::rand() % numStr.size();
int j;
do {
j = std::rand() % numStr.size();
} while (j == i); // ensure different positions
// Form the two-digit string
std::string result;
result.push_back(numStr[i]);
result.push_back(numStr[j]);
return result;
}
int main() {
std::srand(std::time(0));
long long num = 1234567;
std::string randomTwo = getRandomTwoDigits(num);
std::cout << "Random two digits: " << randomTwo << std::endl;
}
/*
run:
Random two digits: 41
*/