Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add symbol function to string module #943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}

Loading