Random Generation of Characters

T

Tj Superfly

How could you generate a list of all possible combination's of lowercase
letters (a-z) and numbers (0-9).

Example: ztd6dnck

Now, I know of ways I can do this, but it's definitely not the most
efficient or fastest way possible, which is why I'm reaching out to this
community. It would be extremely nice if the program would do it in some
type of order (aaaaaaaa, aaaaaaab...etc. - or something along those
lines) because then it would know when it's complete. There can NOT be
ANY repeats, and it must include all combination's.

I know, it's a lot of combination's, which is why if I am going to
tackle this task, it needs to be done right.

I would want the list to be in an array which I could then export to a
yaml file and save for later use.

The only way I would know how to do it is if it randomly generated them,
pushed them into an array, and checked each one it generated against the
array to see if it exists already. I would never truly know if the list
is complete, because it would always be checking itself. So,
suggestions, codes, help?!?!

Thanks to everyone in advance, I know this is a relatively large task,
but this is a powerful community and programming language and I know it
can be done.
 
B

Bill Kelly

From: "Tj Superfly said:
How could you generate a list of all possible combination's of lowercase
letters (a-z) and numbers (0-9).

Example: ztd6dnck

Now, I know of ways I can do this, but it's definitely not the most
efficient or fastest way possible, which is why I'm reaching out to this
community. It would be extremely nice if the program would do it in some
type of order (aaaaaaaa, aaaaaaab...etc. - or something along those
lines) because then it would know when it's complete. There can NOT be
ANY repeats, and it must include all combination's.

If you didn't need mixed letters and numbers, you could use: (for
example)

("aaa".."zzz").to_a


For mixed letters and numbers, you could use base 36.

Note, if you really want eight characters width, you are talking about a
*huge* number of strings here...
=> 2821109907455

Two point eight trillion....

So... You could do...

0.upto("zzzzzzzz".to_i(36)) {|n| puts n.to_s(36)}

...but it would take a long time to finish. :)

I would want the list to be in an array which I could then export to a
yaml file and save for later use.

The number of items in the list is too big for this to be practical. What
problem are you trying to solve?


Regards,

Bill
 
T

Tj Superfly

Perhaps this would be more practical if it was put into a MySQL
database?

This isn't much of solving a problem then it is of completing the list.
Basically, these codes are used for images, some already exist and some
don't. I already have a program that checks to see if images exist and
deletes them from the file, so once I have a list, it would be easy for
me, but a long process for the computer.

I'm not sure, 2.8 trillion is a lot, perhaps I should give up. x_X
 
R

Robert Klemme

How could you generate a list of all possible combination's of lowercase
letters (a-z) and numbers (0-9).

Just a note: this is by no means random. It seems you rather want all
*combinations* of letters and numbers.

Another remark: if you do not limit the length the number of such
combinations is unlimited as well.
I would want the list to be in an array which I could then export to a
yaml file and save for later use.

IMHO reading a large set of these strings is not necessarily faster than
generating them when needed. This depends however on what you want to
do with this. Can you disclose more detail about the problem you are
trying to solve?
The only way I would know how to do it is if it randomly generated them,
pushed them into an array, and checked each one it generated against the
array to see if it exists already. I would never truly know if the list
is complete, because it would always be checking itself. So,
suggestions, codes, help?!?!

Yes, this is a completely nonsensical approach for the type of problem
at hand.
Thanks to everyone in advance, I know this is a relatively large task,
but this is a powerful community and programming language and I know it
can be done.

The task is not that hard. You'll might even find an implementation of
combinations in the RAA.

Kind regards

robert
 
T

Tj Superfly

Okay, why not! Here's what I'm trying to do.

The website has urls for all their pet images, each having one of the
random combination's inside of it. As such:

http://pets.neopets.com/cp/rbm2vqzv/1/2.png

So, basically I want to create some sort of list / program that searches
though them and tells me if they exist or not, so I can see new pets
when they are eventually uploaded.

P.S. That's where I got random generation, because each url is random,
but I guess ultimately my list is 'complete' so, sorry about that.

Best Regards,

TJ
 
E

Eric I.

Okay, why not! Here's what I'm trying to do.

The website has urls for all their pet images, each having one of the
random combination's inside of it. As such:

http://pets.neopets.com/cp/rbm2vqzv/1/2.png

So, basically I want to create some sort of list / program that searches
though them and tells me if they exist or not, so I can see new pets
when they are eventually uploaded.

P.S. That's where I got random generation, because each url is random,
but I guess ultimately my list is 'complete' so, sorry about that.

Best Regards,

TJ

First realize that if you're looking for an 8 digit sequence, where
each digit is one of 36 characters, then there are 36**8, or
2,821,109,907,456 combinations. Are you really going to hit the web
site with nearly 3 trillion requests? And if you try, can we place
bets on which will happen first:

1) You get contacted by the web site's lawyers.
2) You get contacted by a law enforcement agency.
3) You get cut off by your ISP.

That said, the following code will generate all 46,656 possibilities
of size 3 (and by changing one variable you can get combinations of a
different size):

char_count = 3
base = 36

0.upto(base**char_count - 1) do |value|
puts value.to_s(base).rjust(char_count, '0')
end

Eric

====

LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE
workshops. Please visit http://LearnRuby.com for all the details.
 
T

Tj Superfly

Haha, that sounds funny, but is so true. :(

I know there is a website with resources to do this though. I'm not sure
if they cracked the encryption or if they literally have a lot of lists
everywhere.

Chances are, this will never be complete, but if anyone has any
brilliant ideas, please do post them. :)

Regards,

TJ
 
B

Bill Kelly

From: "Tj Superfly said:
Okay, why not! Here's what I'm trying to do.

The website has urls for all their pet images, each having one of the
random combination's inside of it. As such:

http://pets.neopets.com/cp/rbm2vqzv/1/2.png

So, basically I want to create some sort of list / program that searches
though them and tells me if they exist or not, so I can see new pets
when they are eventually uploaded. [...]
I know there is a website with resources to do this though. I'm not sure
if they cracked the encryption or if they literally have a lot of lists
everywhere.

How do *humans* find that link, above? Is it possible to find that
picture starting from www.neopets.com and clicking around on links?

I.e. is there a way to spider the site and find these images?


Regards,

Bill
 
T

Tj Superfly

Theoretically yes, but that wouldn't be efficient because ultimately the
goal is to find ones that are not yet posted on the site.
 
R

Robert Klemme

2008/6/29 Tj Superfly said:
Okay, why not! Here's what I'm trying to do.

The website has urls for all their pet images, each having one of the
random combination's inside of it. As such:

http://pets.neopets.com/cp/rbm2vqzv/1/2.png

So, basically I want to create some sort of list / program that searches
though them and tells me if they exist or not, so I can see new pets
when they are eventually uploaded.

P.S. That's where I got random generation, because each url is random,
but I guess ultimately my list is 'complete' so, sorry about that.

IMHO a far better approach is to crawl the site and record all image
URL's (they must linked somewhere) and note the difference to last
visit. This will put less load on the target server and be generally
faster than trying all possible combinations.

Kind regards

robert
 
J

Jano Svitok

Perhaps this would be more practical if it was put into a MySQL
database?

This isn't much of solving a problem then it is of completing the list.
Basically, these codes are used for images, some already exist and some
don't. I already have a program that checks to see if images exist and
deletes them from the file, so once I have a list, it would be easy for
me, but a long process for the computer.

I'm not sure, 2.8 trillion is a lot, perhaps I should give up. x_X

I guess you should change the other part of your program to not rely
on having the list explicitly available.
The list itself is over 20 TB in size, not counting any overhead.
For example, if you just store a list of deleted items and available
images, you may save
a lot of time and memory/disk.

So once again, what problem are you trying to solve? (Hint: it looks
like it's something about images)
If you describe your intent from the high-level perspective, somebody
may help you with a different approach.
It's like painting - most of the time you have to be close to the
canvas, but from time to time you have to step back and
see the whole picture.
 
M

Michael Fellinger

How could you generate a list of all possible combination's of lowercase
letters (a-z) and numbers (0-9).

Example: ztd6dnck

Now, I know of ways I can do this, but it's definitely not the most
efficient or fastest way possible, which is why I'm reaching out to this
community. It would be extremely nice if the program would do it in some
type of order (aaaaaaaa, aaaaaaab...etc. - or something along those
lines) because then it would know when it's complete. There can NOT be
ANY repeats, and it must include all combination's.

order = 'aaaaaaaa'
# "aaaaaaaa"
order.succ!
# "aaaaaaab"
order.succ!
# "aaaaaaac"
order.succ!
# "aaaaaaad"
100_000.times{ order.succ! }
# 100000
order
# "aaaafryh"

No need to store all previous combinations, just the last one to continue.

^ manveru
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top