PDA

View Full Version : Mass word generator



ubergeek85
13-03-2009, 02:43 PM
Hi all. I'm looking for a program to generate random words/strings. I've been googling, but haven't found much freeware. It has to be able to generate words to a filter (eg: llnnllnn = ah78yr88) en masse. Can anyone suggest anything? Thanks.

Speedy Gonzales
13-03-2009, 02:49 PM
I have no idea what youre talking about

ubergeek85
13-03-2009, 02:53 PM
I'll admit, it's a bit hard to explain. I'm after a program that generates lots of random strings, can save thise strings to a text file, and I can change how it generates the string, eg the first char has to be a letter, second char has to be a number, etc.

Make sense? :sleep I almost put myself to sleep.

Erayd
13-03-2009, 03:16 PM
I could write that in my sleep. Is Linux-based OK?

Bantu
13-03-2009, 04:19 PM
Search Lorem Ipsum
It is a random generator. There are quite a few online generators.

http://www.lipsum.com/

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

dyewitness
13-03-2009, 04:48 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Random Word Generator</title>
<script language="javascript" type="text/javascript">

var validCharacters = new Array();
validCharacters[0] = "a";
validCharacters[1] = "b";
validCharacters[2] = "c";
validCharacters[3] = "d";
validCharacters[4] = "e";
validCharacters[5] = "f";
validCharacters[6] = "g";
validCharacters[7] = "h";
validCharacters[8] = "i";
validCharacters[9] = "j";
validCharacters[10] = "k";
validCharacters[11] = "l";
validCharacters[12] = "m";
validCharacters[13] = "n";
validCharacters[14] = "o";
validCharacters[15] = "p";
validCharacters[16] = "q";
validCharacters[17] = "r";
validCharacters[18] = "s";
validCharacters[19] = "t";
validCharacters[20] = "u";
validCharacters[21] = "v";
validCharacters[22] = "w";
validCharacters[23] = "x";
validCharacters[24] = "y";
validCharacters[25] = "z";

function randomiser() {
var outputDiv = document.getElementById("output");

var numberOfWords = document.forms[0].numberOfWords.value;
var wordPattern = document.forms[0].wordPattern.value;

outputDiv.innerHTML = "";

var randomWordsHTML = "";


for (var i = 1; i <= numberOfWords; i++) {
var randomWord = generateRandomWord(wordPattern);

randomWordsHTML += randomWord + "<br />";
}

outputDiv.innerHTML = randomWordsHTML;
}

function generateRandomWord(wordPattern) {
var randomWord = "";
var wordLength = wordPattern.length;

for (var i = 0; i < wordLength; i++) {
if (wordPattern.charAt(i) == "l") {
randomWord += validCharacters[getRandomNumber(25)];
} else if (wordPattern.charAt(i) == "n") {
randomWord += getRandomNumber(9);
}
}

return randomWord;
}


function getRandomNumber(max) {
return Math.floor(Math.random() * (max + 1));
}
</script>
</head>
<body>
<form action="#">
Number of words: <input type="text" name="numberOfWords" />
<br />
Word pattern: <input type="text" name="wordPattern" /> (eg. lllnn, will generate words of length 5 made of 3 letters ('l') and 2 numbers ('n'))
<br />
<input type="button" name="randomise" value="Generate Random Words" onclick="randomiser();" />
</form>
<br />
<h2>Output</h2>
<hr />
<div id="output">
</div>
</body>
</html>


Save to an html file and run in your browser.
Then you have to copy/paste words into your text file.

Erayd
13-03-2009, 05:17 PM
And here's a C one. First argument is the number of strings to generate, second argument is the format code (l=letter, n=number, s=symbol), third argument is an optional filename. If you don't specify a filename, it'll print the strings to the console instead.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main(int argc, char **argv) {
//vars
long i, limit;
int i2;
const char *letters = "abcdefghijklmnopqrstuvwxyz";
const char *numbers = "0123456789";
const char *symbols = "~!@#$%^&*()_+=-`{}|[]\\:\";'<>?,./";
char *outstr;
FILE *fh;

//count args
if(argc < 3) {
printf("Not enough arguments!\n");
exit(EXIT_FAILURE);
}

//open file handle
if(argc > 3) {
fh = fopen(argv[3], "w");
if(fh == 0) {
printf("Unable to open file!\n");
exit(EXIT_FAILURE);
}
}

//seed prng
int seed = (int) time(0);
srandom(seed);

//generate strings
limit = strtol(argv[1], 0, 10);
printf("Generating %ld random strings...\n", limit);
outstr = malloc(sizeof(char) * (strlen(argv[2]) + 1));
outstr[strlen(argv[2])] = '\n';
for(i = 0; i < limit; i++) {
for(i2 = 0; i2 < (int) strlen(argv[2]); i2++) {
switch(argv[2][i2]) {
case 'l':
outstr[i2] = letters[(int) (random() % strlen(letters))];
break;
case 'n':
outstr[i2] = numbers[(int) (random() % strlen(numbers))];
break;
case 's':
outstr[i2] = symbols[(int) (random() % strlen(symbols))];
break;
default:
printf("Invalid format string!\n");
exit(EXIT_FAILURE);
break;
}
}
//print to console if no filename given, otherwise write to file
if(argc < 4) {
printf("%s", outstr);
}
else {
fwrite(outstr, strlen(outstr), 1, fh);
}
}

//cleanup
free(outstr);
if(argc > 3) {
fclose(fh);
}

//quit
exit(EXIT_SUCCESS);
}

dyewitness, are you are aware that you can specify an array all in one go? Just use new Array('a', 'b', 'c'); etc.

dyewitness
13-03-2009, 05:27 PM
...
dyewitness, are you are aware that you can specify an array all in one go? Just use new Array('a', 'b', 'c'); etc.

Yes.

Erayd
13-03-2009, 05:28 PM
Yes.

Then why slow things down and add a ton of extra code by doing one letter per line?

Edit: You can access strings by index in javascript anyway, so you don't actually need to declare it as an array at all - just specify it as a string 'abcdefghi...', then access individual characters in the same way you would elements of an array.

dyewitness
13-03-2009, 05:37 PM
Heh, it's a javascript solution so it's going to be slow anyway compared to your C version, but has the benefit of no compilation and browser based

Having said that:
- 26 extra lines is hardly going to add much overhead
- it is a rush job, so coding style isn't high on the priorities
- I was going to do something else with it, but changed my mind, and the explicit array init just stayed as is
- it can always be refactored
- does it really matter?

Erayd
13-03-2009, 05:45 PM
Heh, it's a javascript solution so it's going to be slow anyway compared to your C version, but has the benefit of no compilation and browser basedYup. Your solution automatically wins on the grounds of being far more immediately usable - just save it somewhere and point a browser at it :thumbs:. I'm just a sucker for excessively optimised code. It doesn't really matter... I'm a pedant, arrays like that are the stuff my nightmares are made of (that, and the forum clock) :rolleyes:.

dyewitness
13-03-2009, 05:53 PM
Yup. Your solution automatically wins on the grounds of being far more immediately usable - just save it somewhere and point a browser at it :thumbs:. I'm just a sucker for excessively optimised code. It doesn't really matter... I'm a pedant, arrays like that are the stuff my nightmares are made of (that, and the forum clock) :rolleyes:.

That's the beauty of refactoring, you can go back and fix the monkey code ;).

Erayd
13-03-2009, 05:54 PM
That's the beauty of refactoring, you can go back and fix the monkey code ;).

Yes... I'm currently trying to restrain myself and get on with the stuff I'm *supposed* to be doing...

robsonde
13-03-2009, 06:04 PM
Hi all. I'm looking for a program to generate random words/strings. I've been googling, but haven't found much freeware. It has to be able to generate words to a filter (eg: llnnllnn = ah78yr88) en masse. Can anyone suggest anything? Thanks.

what do you want this for??

looks like random passwords......

Sweep
13-03-2009, 07:12 PM
But a random string by definition depends on the seed for the output. If the seed itself is not random as in generate output by typing in the seed as in the example given.

It is, of course, highly unlikely that I could guess the outcome but if you were to type in the same letters each time then where comes the random event to change the output?

Erayd
13-03-2009, 08:29 PM
But a random string by definition depends on the seed for the output. If the seed itself is not random as in generate output by typing in the seed as in the example given.

It is, of course, highly unlikely that I could guess the outcome but if you were to type in the same letters each time then where comes the random event to change the output?Sweep, the example string wasn't a seed - it was a format key specifying which characters should be a random letter and which should be a random number.

The javscript prng is automatically seeded, I'm not sure where from (probably implementation-specific). The C program I wrote above uses the unix epoch (number of seconds since 12:00am, January 1st 1970) as the prng seed - you could make this more precise, or add an additional source of entropy, if you wanted to make the output more random.

I'd initially planned to seed from /dev/urandom, but I wasn't sure what kind of system Geekster was running and wanted to be sure it would work on his system.

Sweep
13-03-2009, 08:50 PM
Sweep, the example string wasn't a seed - it was a format key specifying which characters should be a random letter and which should be a random number.

The javscript prng is automatically seeded, I'm not sure where from (probably implementation-specific). The C program I wrote above uses the unix epoch (number of seconds since 12:00am, January 1st 1970) as the prng seed - you could make this more precise, or add an additional source of entropy, if you wanted to make the output more random.

I'd initially planned to seed from /dev/urandom, but I wasn't sure what kind of system Geekster was running and wanted to be sure it would work on his system.

Output more random? The output should be random or not in my opinion.
What is more random than random? Possibly hook up inputs into a forest and wait until a certain tree falls over.

It is not over to me to guess what the original poster want or needs.

The most elegant solution may be best.

But the OP asked a question. It is not for me to question your programming skills as you have done with another member.

Erayd
13-03-2009, 10:55 PM
...It is not for me to question your programming skills as you have done with another member.Then I offer my sincere apologies to dyewitness - that was not my intention, and I'm sorry if that's the way it came across. I guess I just got caught up in 'pedantic coder' mode.

Regarding your comments about randomness, there's actually so such thing as a truly random number generator - hence 'pseudo-random'. As you say, a prng is only ever as random as its seed. Most generators work on the basis of selecting numbers in sequence from a *very* large set produced by an algorithm. The seed determines the order and / or starting position of the set. The more entropy is in the seed, the more unpredictable the output - that's what I meant by 'more random'.

ubergeek85
15-03-2009, 06:34 PM
Thanks everyone, this will compliment my random bang generator quite nicely.

I think I'll go for Erayd's version (looking at generating a lot of strings). I'm using windows, but I've got a few Linux VM's lying around.


what do you want this for??

looks like random passwords......

pfft, I've already got password generators. This is for usernames!

Erayd
15-03-2009, 08:02 PM
...I'm using windows, but I've got a few Linux VM's lying around.That code *should* compile in Windows - you probably won't need Linux - but note I haven't tested it under anything other than Linux.

If you do decide to run it under Linux, are you OK to compile that yourself or do you want me to compile a binary for you? If so, do you want one for x86 or x86_64?

ubergeek85
16-03-2009, 10:03 AM
I should be OK to compile it myself. Turns out that despite the fact that I have both Microsoft Visual Studio and Dev-c, neither of them complie straight C, only C++! Ah well, off to google I go.

Also, dyewitness, your one works pretty good, but seems to go on the go-slow, and sometimes locks up Firefox. Although I am generating 500000 strings!

dyewitness
16-03-2009, 03:43 PM
I should be OK to compile it myself. Turns out that despite the fact that I have both Microsoft Visual Studio and Dev-c, neither of them complie straight C, only C++! Ah well, off to google I go.

Also, dyewitness, your one works pretty good, but seems to go on the go-slow, and sometimes locks up Firefox. Although I am generating 500000 strings!

Aha, I didn't bother testing that sort of volume, only tried 5000.
Best off going for the compiled program then.

Erayd
16-03-2009, 06:06 PM
...although I am generating 500000 strings!Just tested this quantity - it takes on average 0.215 seconds to generate an 8.2MB file containing 500,000 strings using the format string 'nlnlnlnlnlnlnlnl' (8 numbers, 8 letters). Further testing with larger quantities suggest that this will scale in a more or less linear fashion, provided your storage backend can keep up.

Test environment is Gentoo Linux, custom kernel 2.6.28-gentoo-r1-neith-1, compiled using gcc-4.3.3 with -O2, amd64 arch. No processor-specific optimisations. System is C2D E6550 (2.33GHz, 1333MHz FSB) running at stock speeds with 4GB DDR2-800 ram.

Test results:
steve@neith:~$ time strgen 500000 nlnlnlnlnlnlnlnl test.txt && ls -sh test.txt
Generating 500000 random strings...

real 0m0.243s
user 0m0.215s
sys 0m0.027s
8.2M test.txt
steve@neith:~$ time strgen 5000000 nlnlnlnlnlnlnlnl test.txt && ls -sh test.txt
Generating 5000000 random strings...

real 0m3.014s
user 0m2.215s
sys 0m0.265s
82M test.txt
steve@neith:~$ time strgen 50000000 nlnlnlnlnlnlnlnl test.txt && ls -sh test.txt
Generating 50000000 random strings...

real 0m25.259s
user 0m21.023s
sys 0m2.740s
812M test.txt

adslgeek
18-03-2009, 09:28 PM
Man you guys fricken rock! What on earth is the random text in aid of?

Cheers
ADSL Geek
http://www.adslgeek.com