Windows Defender and C++ time problem

Hey I have just finished creating the Triplex game with C++ and I’m loving the course so far! I’ve had no problems until the very end when I use the codes #include & srand(time(NULL));

When I try to run Triplex on the terminal I get the error “The system cannot execute the specified program.” and then my anti virus pops up saying Trojan:Win32/Wacatac.B!ml which is obviously false. When I check the location it is indeed Triplex.exe so what is up?

It must be something to do with the complier and the clock on the computer or something? Here’s my code, thank you.

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
    std::cout << "\n\nYou're a secret agent breaking into a level " << Difficulty;
    std::cout << " secure server room...\nYou need to enter the correct codes to continue...\n\n";
bool PlayGame(int Difficulty)

    const int CodeA = rand() % Difficulty + Difficulty + Difficulty;
    const int CodeB = rand() % Difficulty + Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty + Difficulty;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // Print CodeSum and CodeProduct to the terminal
    std::cout << "+There are 3 numbers in the code";
    std::cout << "\n+The codes add-up to: " << CodeSum;
    std::cout << "\n+The codes multiply to give: " << CodeProduct << std::endl;

    // Store player guess
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    // Check if the players guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
        std::cout << "\n*** Well done agent! You have extracted the file! Keep going ***";
        return true;
        std::cout << "\n*** You have entered the incorrect code! Careful agent! Try again! ***";
        return false;

int main()
    srand(time(NULL)); // Creates new random sequence based on time of day
    int LevelDifficulty = 1;
    const int MaxDifficulty = 10;
    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clears any errors
        std::cin.ignore(); // Discards the buffer 
        if (bLevelComplete) 
    std::cout << "\n*** Great work agent! You got all the files! Now get out of there! ***\n";
    return 0;

Could you tell me if using <random> instead fixes that?

#include <random>

int RandInt(int Min, int Max)
    static std::mt19937 Engine{std::random_device{}()};
    return std::uniform_int_distribution<>{Min, Max}(Engine);

And then used like

const int CodeA = RandInt(Difficulty * 2, Difficulty * 3 - 1);

You can then remove srand(time(NULL))

Hey this did work but I’m curious as to why the other way caused Windows Defender to freak out!

I’m going to report it as a false positive on Thanks for the swift reply, keep up the good work!

I’m not entirely sure since I don’t get it on my end so not sure which function specifically is the culprit. Though there is a talk “rand() Considered Harmful”

That details the shortcomings of rand().

EDIT: The PR was rejected due to concerns.

I’m actually in the process of submitting a pull request to Microsoft’s C++ Standard library to implement one of the features in a Technical Specification (think “beta”) that proposes randint (will probably be renamed to rand_int or random_int if it gets merged to the standard) which is effectively the code I posted above.

So if it gets accepted then in a later version of Visual Studio 2019 (16.6 at the earliest) then you would be able to write

#include <experimental/random>

int main()
    int A = std::experimental::randint(0, 2); //random number between [0-2]

Though it being within experimental means it’s a bit verbose to type but you can just use a namespace alias

#include <experimental/random>
//make "stdexpr" just another way to say "std::experimental"
namespace stdexp = std::experimental; 

int main()
    int A = stdexp::randint(0, 2); //random number between [0-2]

Hmm that’s interesting considering this is on a fresh OS installation, I thought it would of been more of a common problem! That’s interesting about rand() too. I had no idea but at the same time I had no problems with it until I used #include & srand(time(NULL)); which led me to believe it was due to the exe trying to detect the time on the OS and Windows Defender started to freak out over it.

I did report it as a false positive and i’m soon getting a fresh SSD so I’m going to redo Triplex using the original code and see if it still detects it as a treat with those settings just for curiosity sake… altho it’s weird if nobody else has this problem!

There have been others. It’s weirdly hit or miss which I don’t quite understand :man_shrugging:.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms