Login Register






[Python, Scala, Java] Wordgenerator filter_list
Author
Message
RE: [Python, Scala, Java] Wordgenerator #4
(06-06-2013, 02:08 PM)Deque Wrote: You create random words.
I generate all possible words (mathematically spoken I generate all variations of characters with repetition).

I'm not very familiar to Python, I just try to understand what I see, and I think your code takes litters from the alphabet and puts them in all possible orders to make always new words (meaning it repeats also the same char in the same word, which thing my code misses). Correct me if I'm wrong.

My code instead takes the given alphabet and builds words long according to the given range following the array order (example: alphabet: a,b,c,d,e; range: 1,3; it thus adds to the generated words "a", "ab", "abc"), then shuffles the array order, so that we can have (e.g.) b,c,a and does it all again.

Quote:And: I am not familiar with PHP, but you seem to create an array or a list of words. I believe PHP doesn't support lazy evaluation, which means you compute all the words before you return them to the caller.

For what I know, you're right, PHP does not support lazy evaluation, but I'm not doing it. I define $genOut as an array before starting the main loop. If you instead mean the one used for $randPick, well, I'm not sure about it, so I just changed it in the code beneath updated.

Quote:It can also not be used for bruteforcing, because you will at some point create the same words again, randomly.

You're right here again, but, in case you thought so, my code does not give as output wordlist repeated words as it checks whether the new word as been already generated or not.

[quote]
Here is the program, I understand you did, in Python: (4 lines of code as defined by cloc, which means function declaration and imports are included)

Code:
import random def rand_word(alphabet, min, max, number): randword = lambda a, l: [random.choice(a) for i in xrange(l)] return [ randword(alphabet, random.randrange(min, max+1)) for i in xrange(number) ]

If I'm not wrong, this should append also words already generated in the output array, shouldn't it?

Also, I actually had two bugs I just noticed in my code:

PHP Code:
function wordGenerator(alphabet, m, n, o) { $genOut = array(); for (i = 0; i => o; i++) { $x = rand(m, n); $randPick = array(array_slice(alphabet, 0, $x)); $randWord = ""; // I wasn't reseting randWord at each loop foreach ($randPick as $randValue) { // and thus $randWord .= $randValue; // here randWord kept on adding new litters making always bigger words } if (!isset($genOut[$randWord])) { // this part adds the new word only if is new in the array, but if it's not then we'll have less words then the number it was demanded in the end, as we don't add anything $genOut[] = $randWord; } else { $i = $i - 1; // this code was added to prevent what mentioned above. here we decrease the value of $i, so we'll try and add a new word the next loop } shuffle(alphabet); } }
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply





Messages In This Thread
[Python, Scala, Java] Wordgenerator - by Deque - 06-04-2013, 08:54 PM