0

I have that funtion for generate sequence to the style 'hqhzaw', 'ebcpm', 'qtch', etc. (only letters) and according to 'lenght'

string random_letter(int length) {
	string s;

	for (int i = 0; i < length; i++) {
       		s += char(rand() % 26 + 97);
	}

	return s;
}

I want to generate, using this funtion or some other, array of letters and numbers to the style 'tn4v9k2e0', '8ezt0p3', 5cye7' according to 'lenght'.

Thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rafaelbrizu
0

instead of using the ascii codes which would get a bit more complicated when you add numbers because of the disconnect between the codes (since numbers are 48-57 and letters 97-122), why don't you try something like the following as a starting point:

string random_letter(int length) 
{
     const string values = "abcdefghijklmnopqrstuvwxyz";
     const int valuesSize = 26;
     string s;

     for (int i = 0; i < length; i++) 
     {
          s += values[rand() % valuesSize];
     }

     return s;
}

then you can add whatever characters you want (numbers), just a suggestion.

~J

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.