57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
|
//
|
||
|
// Created by DH10MBO on 13.11.2024.
|
||
|
//
|
||
|
|
||
|
#include "Mastermind.h"
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <ostream>
|
||
|
#include <random>
|
||
|
|
||
|
int getRandomNumberInRange(int min, int max) {
|
||
|
static std::mt19937 generator(static_cast<unsigned int>(time(nullptr)));
|
||
|
std::uniform_int_distribution<int> distribution(min, max);
|
||
|
|
||
|
int randomNumber = distribution(generator);
|
||
|
|
||
|
return randomNumber;
|
||
|
}
|
||
|
|
||
|
void printAllStringsInVector(std::vector<std::string> &strings) {
|
||
|
std::cout << "[";
|
||
|
int i;
|
||
|
for (i = 0; i < strings.size() - 1; i++) {
|
||
|
std::cout << strings[i] << ", ";
|
||
|
}
|
||
|
std::cout << strings[i] << "]" << std::endl;
|
||
|
}
|
||
|
|
||
|
std::vector<std::string> generateSecretCode(int digits, int optionsPerDigit) {
|
||
|
std::vector<std::string> secretCode;
|
||
|
|
||
|
for (int i = 0; i < digits; i++) {
|
||
|
int digit = getRandomNumberInRange(0, optionsPerDigit);
|
||
|
secretCode.push_back(std::to_string(digit));
|
||
|
std::cout << "Secret Code was set as " << digit << std::endl;
|
||
|
}
|
||
|
|
||
|
return secretCode;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void Aufg5Main() {
|
||
|
// generateSecretCode(1,1);
|
||
|
|
||
|
std::vector<std::string> SecretCode = generateSecretCode(4, 4);
|
||
|
|
||
|
printAllStringsInVector(SecretCode);
|
||
|
|
||
|
|
||
|
}
|