Create random word list

Posted By: FeiHongJr

Create random word list - 12/20/07 10:23

Just curious if anyone has any thoughts on how to implement this idea.

Basically I want to create a random 'word' list using characters,numbers and possibly symbols and have that info printed out to a .txt file as it generates.

For example:

Using the A a B b 1 2 as an example

I would like the code to generate all possible combinations so...

A
Aa
AA
AB
Ab
A1
A2
a
aA
aa
aB
ab
a1
a2
B
BA
Bb
etc...

Then write them to a .txt file in that format as they are generated. Does anyone have any ideas?
Posted By: adoado

Re: Create random word list - 12/20/07 11:08

Maybe fill an array with the characters. The array only would hold a pointer to a string, though. Then loop through the array and loop inside the loop again to add a second letter. Something like:

Code:

var ArrayOfChars[6];

..

function SetupChars()
{
ArrayOfChars[0] = str_create("A");
ArrayOfChars[1] = str_create("a");
ArrayOfChars[2] = str_create("B");
ArrayOfChars[3] = str_create("b");
ArrayOfChars[4] = str_create("1");
ArrayOfChars[5] = str_create("2");
}

var i;
var k;

string first;
string second;
string final;


function CreateWords()
{
while(i != 6)
{
while(k != 6)
{
first = ptr_for_handle(ArrayOfChar[I]);
second = ptr_for_handle(ArrayOfChar[K]);
str_cat(first, second);
//so something with final word combination
final = first;
k += 1;
}
i += 1;
}
}




This is not tested (may not work), and straight of the top of my head. It is probably not a very good method, either. If you were using a long list of different characters it might be better to work with ASCII numbers and convert them back into strings rather than use strings straight off..

Hope it helps,
Adoado
Posted By: FeiHongJr

Re: Create random word list - 12/20/07 12:34

Thanks, Ill have to look at it when im not so tired.

I have a script that does basically this but is javascript and cant figure out how to convert it over. Heres the code...

Code:
 

var current = "";
var set = new Array('a', 'B', '3', '-');

function init()
{
for (var i = 1; i <= set.length; ++i)
go(0, i);
}

function go(pos, maximum)
{
if (pos == maximum)
{
document.write(' current );
return;
}

for (var i = 0; i < set.length; ++i) {
var tmp = current;
current += set[i];
go(pos + 1, maximum);
current = tmp;
}
}



The above code generates a list like so

a
B
3
-
aa
aB
a3

and so on but is for javascript.
Again thanks for all and any help.
© 2024 lite-C Forums