/****************************************************************************** * This program generates random bytes. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #define NDEBUG #include "Utils.hpp" #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); if (argc != 4) { wcout << L"Syntax: " << Utils::UTF8_to_wstring(argv[0]) << L" min max count" << endl; exit(1); } int min = Utils::stoiWithDefault(Utils::UTF8_to_wstring(argv[1]), 0); int max = Utils::stoiWithDefault(Utils::UTF8_to_wstring(argv[2]), 0); int count = Utils::stoiWithDefault(Utils::UTF8_to_wstring(argv[3]), 0); int diff = max - min + 1; precondition(min >= 0 && min <= 255, "min >= 0 && min <= 255"); precondition(max >= 0 && max <= 255, "max >= 0 && max <= 255"); precondition(max > min, "max > min"); srand(time(0)); unsigned char b; for (int i = 0; i < count; ++i) { b = (unsigned char)(min + int(diff * (rand()/(RAND_MAX + 1.0)))); cout.put(b); } cout << flush; return 0; }