Capitalization

Can I randomize it to include numbers, special symbols and capitalization?
And to start with every one digit and progress through every possible combination up to a specific bound?
Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #include <iostream>
#include <time.h>

using namespace std;
int main() {
	char c;
	int r, i, num = 10000;
	srand(time(NULL));    // initialize the random number generator
	for (i = 0; i < num; i++) {
r = rand() % 26;   // generate a random number
c = 'a' + r;            // Convert to a character from a-z
cout << c;
}
}
Last edited on
yes.
but its easier to make your own table instead of using the ascii table for this.
eg
string c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$@";
cout << c[rand()%c.length()];

and processing every combo is not too bad either, that just depends on how you want to do it. there are an unholy number of possible combinations of arbitrary lengths of the above string. After length gets past about 5 you will be in for a bit of a delay.
Last edited on
True, but I would like it to output like this:

a
b
c
d
...

and vice versa. After z it wild go up to @ or some other character and go on

aa

ab

ac

...
How could I randomize length?
You are looking at implementing a simple adder.

For example, given a number, 23, if I add ONE to it I get 24.
Likewise, if I add one to 99 I get 100.

This is because each digit has eleven possible values: 0..9 and SPACE.
"    "
"    0"
"    1"
"    2"
...
"    8"
"    9"
"   1 "
"   10"

Easy enough. By simply NOT SHOWING combinations where there are spaces to the right of the leftmost non-space, you can do the amazing!

In fact, you can make your adder never wrap around to space, but to 1 from a space and to 0 from a non-space. Then you get the proper sequence:
"    0"
"    1"
...
"    8"
"    9"
"   10"
"   11"

Finally, you stop when you have made it through each digit and still have a carry.
"9998"
"9999"
"0000" (but wants to be "10000", because the one carries)

For a random length, it is the same as getting any other random number. Get some N and set s[N] to zero, then start adding at s[N-1] and continue to s[0].

Hope this helps
Last edited on
Topic archived. No new replies allowed.