/ Published in: ASP
Expand |
Embed | Plain Text
'From http://www.4guysfromrolla.com/aspfaqs/ShowFAQ.asp?FAQID=114 Function Shuffle( inArray, needed ) ' find out how many input elements there are... incnt = UBound( inArray ) ' then create the output array to be the size ' requested via the "needed" argument dim outArray redim outArray( needed ) ' now we will select the number of values ' specified as "needed"... For i = 0 To needed ' choose a random number from 1 to our ' current input array usage size... choose = Int( incnt * Rnd(1) ) ' put that chosen element into the next ' slot in the output array... outArray( i ) = inArray( choose ) ' here's the tricky part: Since we just ' used the "choose" element, we don't need ' it any more...we replace it with the last ' element of the in-use part of the array! inArray( choose ) = inArray( incnt ) ' and then we (effectively) shrink the array! ' Next time through the loop, there will be ' one fewer elements in the array to choose ' from...because we have (effectively) deleted ' the one just chosen! incnt = incnt - 1 Next ' return the shuffled output Shuffle = outArray End Function
Comments
Subscribe to comments
You need to login to post a comment.

He was the lights flowing away in the darkness. buy wow accountThese were the days of his wasted life; he saw a star fall from the sky
and disappeared, beijing escort Then he , who entered on covered with flowers, shanghai
escort to success and were of water and where devils and poisonous snakes hissed and crawled. shanghai escort But they had
made their way to success. yy2010.4.7