Group: http://groups.google.com/group/coldfusion/topics
johnhutch <john...@gmail.com> Jun 19 03:40PM -0700 ^
--
hey guys. So I have a more general programming conundrum. I'm loading
several items from an XML file. The'yre loaded into a hash where each
item has a category -- so xml_hash[i][j] would refer to the j post in
i category.
I need to spit out three random items.
This client has a particularly slow server, so it's become a question
on how to do this as efficiently as possible. Obviously, I don't want
it to be possible to spit out the same item more than once.
The two ways I can think of doing this is:
1. Restructure the hash into an array of just xml_array[j] that
contains all items, dropping or relocating the i category. Generate a
rand number from 1 to arraysize and display that item. I then delete
that element and repeat two more times.
2. Keep the original xml_hash[i][j] and generate two random numbers:
1 to the number of categories and 1 to the number of posts in a given
category. THat part's easy. It gets tricky when we start removing
posts from categories and -- if the category then becomes empty,
removing the category.
I'm wondering if anyone can think of a better algorithm. Psuedo-code
appreciated. My coldfusion is a bit weak, so by all means, if the
language has any shortcuts, lemme know! Thanks!
You received this message because you are subscribed to the Google Groups "ColdFusion" group.
To post to this group, send email to coldf...@googlegroups.com.
To unsubscribe from this group, send email to coldfusion+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldfusion?hl=en.