Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 lines (27 sloc)
701 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "random.h" | |
int main() { | |
std::cout << "Die-rolling simulator.\n"; | |
int low, high, nRolls; | |
std::cout << "Enter low: " << '\n'; | |
std::cin >> low; | |
std::cout << "Enter high: " << '\n'; | |
std::cin >> high; | |
std::cout << "Enter number of rolls: " << '\n'; | |
std::cin >> nRolls; | |
int m = (high - low) + 1; | |
std::cout << "modulo is " << m << '\n'; | |
std::vector<unsigned char> results; | |
while (1) { | |
unsigned char c = Random::getRandomByte(); | |
if (c >= 255 - (255 % m)) | |
continue; | |
results.push_back((c % m) + low); | |
if (results.size() == (size_t)nRolls) | |
break; | |
} | |
for (auto& el : results) | |
std::cout << (int)el << " "; | |
std::cout << '\n'; | |
return EXIT_SUCCESS; | |
} |