From 2935a0c727411fca487e21b784d9b47ec2f53004 Mon Sep 17 00:00:00 2001 From: Unnamed Date: Wed, 21 Aug 2019 11:38:30 +0000 Subject: [PATCH] Spam.cpp: small improvements - Chose spam line at random only when source contain more than 1 line - Use UniformRandomInt instead of rand() % count --- src/hacks/Spam.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hacks/Spam.cpp b/src/hacks/Spam.cpp index 394524a7..840372f7 100644 --- a/src/hacks/Spam.cpp +++ b/src/hacks/Spam.cpp @@ -341,17 +341,16 @@ void createMove() { if (current_index >= source->size()) current_index = 0; - if (random_order && source->size()) + if (random_order && source->size() > 1) { - current_index = rand() % source->size(); - int tries = 0; - while (current_index == last_index && tries++ < 1000) + current_index = UniformRandomInt(0, source->size() - 1); + while (current_index == last_index) { - current_index = rand() % source->size(); + current_index = UniformRandomInt(0, source->size() - 1); } } last_index = current_index; - std::string spamString = source->at(current_index); + std::string spamString = (*source)[current_index]; if (FormatSpamMessage(spamString)) chat_stack::Say(spamString, *team_only); current_index++;