This is a discussion on "Useful string jumbler function" within the Classic ASP section. This forum, and the thread "Useful string jumbler function are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Useful string jumbler function
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
Useful string jumbler function
Someone wanted a function to take a comma seperated string and jumble the items around into a different order. I thought I would share this all with you incase it would become handy.
I knocked this up in a few minutes, so apologies if anything is bugged.
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
|
|
#2
|
|||
|
|||
|
|
|
#3
|
|||
|
|||
|
Cool code. A few points (I'm being rather picky here):
- The last 6 lines can be replaced with jumbleStringArray = Join(ItemArray(Counter), ",") - Why Randomize so much? Just one at the start of the function does exactly the same. - The tempflag2 = 999999999 isn't needed. - Why the do-loop bit in the middle? If it's random then it should allow a swap of index 3 with index 3, for example. - I'd make the * 5 actually based on the size of the array - doing 5 loops wouldn't be sufficient on a large array. - Doing it this way obviously wouldn't be wholey random - there are much slicker solutions for properly randomizing. Here's mine, it's not optimised (the keep-looping-till-we-get-an-unused-index bit is rather crappy) but it seems to run fast enough. Should be perfectly random:
|
|
#4
|
|||
|
|||
|
|
|
#5
|
||||
|
||||
|
Hi... <blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">The tempflag2 = 999999999 isn't needed.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">I actually used a do while loop initially, so I guess I forgot to take this out.<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">Why the do-loop bit in the middle? If it's random then it should allow a swap of index 3 with index 3, for example.<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">Just my personal preference, thats all.<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">I'd make the * 5 actually based on the size of the array - doing 5 loops wouldn't be sufficient on a large array.<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">If you look again, it IS based on the size of the array.... 5 * the number of elements in the array to be precise.<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">Why Randomize so much? Just one at the start of the function does exactly the same.<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">LOL... that was supposed to be outside of the for loop. Well Spotted! (I did say I knocked it up rather quickly)<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">Join(aryResult, strSeperator)<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">Kewl.... never come across that one before. I coulda saved SOOO much time in the past. And you are right.... yer a picky sod. Next time I submt some code, I shall endeavour to pick my brains for hours before-hand to make it as good as possible and not open to nit picks like you!!
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
![]() |
| Tags |
| useful, string, jumbler, function |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get value from SQL string ? | VegaLA | Classic ASP | 5 | Jan 30th, 2008 07:39 |
| string capacity | Don Logan | JavaScript Forum | 11 | Sep 23rd, 2006 20:28 |
| append % to the string | chandra.nowduri | ASP.NET Forum | 1 | Aug 9th, 2006 09:47 |
| Connection String DSN-less | gwx03 | Classic ASP | 11 | Nov 26th, 2003 12:07 |
| dns less connection String | djaccess | Classic ASP | 7 | Oct 5th, 2003 14:34 |