-
Notifications
You must be signed in to change notification settings - Fork 1
StringRandomizer
afaji edited this page Mar 20, 2017
·
2 revisions
StringRandomizer randomly generates a string.
To begin, you have to include
#include "tcrand/string.hpp"
This will enable StringRandomizer and GrammarRandomizer class. Next, you can create your randomizer object as follow:
tcrand::StringRandomizer str_rand;
You may set some parameters for your StringRandomizer, by calling methods below:
- length(N) - generated string's length will be exactly N
- length(Nmin, Nmax) - generated string's length will be from Nmin to Nmax
- charset(E) - E is a regex. Every characters in your string are going to match E.
- first_charset(E) - E is a regex. The first character in your string is going to match E.
- last_charset(E) - E is a regex. The last character in your string is going to match E.
- palindrome() - generated string will be a palindrome
Once you're done configuring the randomizer, call method `next() to randomly generate a string.
StringRandomizer str_rand;
str_rand.charset("[GTCA]").length(20).palindrome();
cout<< str_rand.next() <<endl;
The code above will generate a palindrome DNA string with a length of 20. The output will be (may vary):
AGGCATCCGTTGCCTACGGA
If you need more complex string generator that can generate a more structured string, see CfgStringRandomizer.