Skip to content

Commit

Permalink
Update string.cpp
Browse files Browse the repository at this point in the history
Added symbol function
  • Loading branch information
Asrith-ufl authored Oct 4, 2024
1 parent 3aef81d commit 1a9035d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/modules/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,26 @@ std::string numeric(GuaranteeMap&& guarantee, const unsigned length, bool allowL
return firstChar + generateStringWithGuarantee(guarantee, targetCharacters, length - 1);
}
}

std::string symbol(int length) {
const std::string specialChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
std::string result;
std::mt19937 generator(static_cast<unsigned int>(std::time(nullptr)));
std::uniform_int_distribution<> distribution(0, specialChars.size() - 1);

for (int i = 0; i < length; ++i) {
result += specialChars[distribution(generator)];
}

return result;
}

std::string symbol(int minLength, int maxLength) {
std::mt19937 generator(static_cast<unsigned int>(std::time(nullptr)));
std::uniform_int_distribution<> lengthDistribution(minLength, maxLength);
int length = lengthDistribution(generator);
return symbol(length);
}

}

0 comments on commit 1a9035d

Please sign in to comment.