Hi Nml:
As usual, your intelect amazes me!
I had to look at your example a few times.. then realized.. I better explain a few things.

First off, your suggestions are very good.. but I'm not quite following along in some parts.. but I think thats because you might not understand the "problem" I have in the first place.. so let me try to explain the situation and "logic" I was following:
I'm using a program called "OtsAV" for the music playout.. its a rather nice piece of software, however, its still quite "under-developed" in its "remote controls" facility (one of the few playout managers. though, that actually has some sort of a remote control facility in the first place!)
Although OtsAV has an extensive "playlist template manager", that part of the program isn't accessable via the RAC (Remote Access Controller) facility.. at all! And, to add salt to the wound.. the RAC is a
unsecured javascript web interface with frames and subsets! OUCH! (cringe)
The RAC can stop, start, play, pause (a stupid feature.. "pause") and search.. and thats about it; using java buttons and http forms! its "nasty" for a poor eggie to interface!
so, heres what *I* did (and I'm the first, to date, to have pulled this off) to make it work; after setting up an IP-based access tunnel (though the server firewall)...
The buttons were easy.. I merely "minick the return code" and send that back "blindly" to the RAC.. and put each set in a proc, attached some logic controllers (like if $DetOT and $DetPY is true/false etc etc) and bind it to a command string (like !play, for example) and boom... works great!
The search facility, however, was a different story alltogether!
Unlike the simple java buttons, The search, however, now requires returned
RESULTS and they come in "index numbers" which had to be converted from song names and other querys.. no easy task.. you'd think they would allow a result to be "handed over" from one operation to another.. NOT THE CASE AT ALL! - thats why the code has 2200 lines in it.. whew! I mention the search because its involved of the next part.. which contains the number gennys...
now I have to give ya a small example of what all this is..
so, lets's say you want to hear "tainted love" by "Soft Cell"..
so you type it in the chatroom:
!search tainted love
The bot now takes that and forwards it via $arg to the command line cgi script (I had fun getting that line out of the javascript!) and then logs into the WEB page interface "on call" and pushes the command through..
Next, the bot has to wait for a reply from the interface.. it then has to parse the entire webpage(s) to extract just the names of the search results AND then to get their index numbers.. more logic determines which kind of page was returned and how it terminates.. (example.. if theres more than 10 results, then a second page is loaded.. up to 5 turns in total to be allowed) then these results are pushed back to $nick to whom requested it (you, in this case) so now the bot will open a PM to you with a list of tracks containing your search query(ies):
DJ 5000 - Search Results for "Tainted Love"
929 - Tainted love - Soft Cell
1623 - Tainted Love - Manson
at this point, you would take the index number and then type in the chatroom: !request 929 at which the bot returns via notice: "your request #929 has been successfully submitted."
the bot passed the index number via another "blind command string" back to the web interface as a "pick #929 and cue as next" while another command sends a "play" directive afterwards...
its really quite CLEVER if you ask me!
now, about the number gennys.. and those "index numbers"..
unfortunately, (as I mentioned above) the RAC doesn't have access to any of the playlist template tools or generators.. it merely sees a "raw list of index numbers".. and thats about it.. -and- these index numbers represent NOTHING more than "index numbers" to the RAC and eggie... and this is a PROBLEM! a nice challenge I had to come up with in order to sort out "what was what" and "how was where"... Now, heres where your suggestions makes sense, in fact, I have allready implemented JUST that.. about the "buckets" and what is where...
The first thing I had to do was (re)sort the "media library" (what they call the index database) so that specific groups of numbers represents specific items that are played- and what items these are.. AND that these numbers CAN (and WILL) change as the library grows (or shrinks) and that these "boundries" are non-fixed.. but must still represent a FIXED value at the time of the parsing. (is this making any sense?) or, in other words: "item 0 to 32 is a promo", "item 33 to 100 is a vocal" and items 101 to the end of the index database is a track"... I'm sure you've gotten the idea!
Now, the NEXT part..
I figured "wow since I have all these nice formatted index numbers.. why not let the bot "auto DJ"?!.. and so, after some thought, I came up with a nice way to do just that.. AUTO DJ! The bot can now
seclectively generate a playlist based on a given (or fixed) playout and/or ruleset..
i.e.
1 promo (rand 1), 5 songs (rand 3), 1 ID (rand 2), 1 promo (rand 1), 4 songs (rand 3), 1 promo (rand 1), 5 songs (rand 3).. and you get the idea.. actually works VERY well in fact.
So, thats what governs the "conditions" of the rands.. they are used to generate "subsets" of playlists based on what the track is- a promo, a vocal or a song entry itself (later I may add more as I figure out ways to resort the media library into GENRES.. but that might be TOO much at this point) at least I got the promos and vocals figured out!
I hope this helps to explain some of my "twisted scripting" you have seen here.. it is a dauting task.. and I'm not a "good programmer".. I only squeeze by with what I need to do to get the job done (at least I TRY to do it right though I'm sure I don't quite succeed

) I have taken a lot of your invalable help and put it to good use in the parsers, and sockets, the callback code.. and now the number gennys just to name a few..
if you ever feel like you'd like to see the whole thing (or even give it a shot and rewrite it

) please let me know! I'll send ya a copy and even give ya access to the RAC..

I think you would be impressed (or, maybe not hehe) at what I was able to accomplish without former programming skills,training, or experience I have you, mindless, Caesar, Fez.. and a few others who have posted various stuff.. and in reading the posts, I have learned and adopted a lot of great minds in writing this thing.. believe it or not.. it hasn't crashed in a long time
I still have a few things to figure out.. like that oauth thing for twitter and a way to multi-thread.. (the search has a problem as when its "busy" with the writeout, the bot does nothing else) oh, and is there a way to expand the output buffer size? (my server can handle more than 3 lines at a time <smile> ) but first, today I need to build a new machine for the playout...
again, thanks Nml and everyone else for al the great help and suggestions- both directly and indirectly!
-DjZ-
UPDATE:
after I wrote this post, I went back and re-read your post and looked at the code example again and DING it CLICKED.. so I DO get what you're saying now!
makes LOTS of sense - I LIKE IT!
as for the inital code, yeah the code I posted is "broken" and was allready fixed; the "rand 3 in []'s for example was an error from when I took out what was inside there and forgot the []'s.. I dumped that entire line of code by this point..
about your code: what I didn't know was that you can incr a NUMBER besides 1.. I have read (by now) that you can.. which is why initally, I didn't understand what you were saying... but, NOW I get it.. (see? my code is FULL of mistakes like that; stuff being done "the long way" because I don't know or understand the commands designed for that task) -DjZ-