| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 98139 | 2009-03-13 01:43:00 | Mass word generator | ubergeek85 (131) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 755960 | 2009-03-13 01:43:00 | 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. | ubergeek85 (131) | ||
| 755961 | 2009-03-13 01:49:00 | I have no idea what youre talking about | Speedy Gonzales (78) | ||
| 755962 | 2009-03-13 01:53:00 | 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. |
ubergeek85 (131) | ||
| 755963 | 2009-03-13 02:16:00 | I could write that in my sleep. Is Linux-based OK? | Erayd (23) | ||
| 755964 | 2009-03-13 03:19:00 | 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. |
Bantu (52) | ||
| 755965 | 2009-03-13 03:48:00 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org <html xmlns="www.w3.org <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. |
dyewitness (9398) | ||
| 755966 | 2009-03-13 04:17:00 | 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. |
Erayd (23) | ||
| 755967 | 2009-03-13 04:27:00 | ... dyewitness, are you are aware that you can specify an array all in one go? Just use new Array('a', 'b', 'c'); etc. Yes. |
dyewitness (9398) | ||
| 755968 | 2009-03-13 04:28:00 | 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. |
Erayd (23) | ||
| 755969 | 2009-03-13 04:37:00 | 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? |
dyewitness (9398) | ||
| 1 2 3 | |||||