Randomise the order of an array ?

Results 1 to 2 of 2

Thread: Randomise the order of an array ?

  1. #1
    Join Date
    Dec 1969

    Default Randomise the order of an array ?

    Does anyone know how to randomise the order of an array, basically to shuffle round the positions where each element is stored ?<BR><BR>ive looked at http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=89 but its kinda hard to follow.<BR><BR>any ideas ?<BR>thanks,<BR>adam

  2. #2
    Join Date
    Dec 1969

    Default RE: Randomise the order of an array ?

    &#060;Script language="JavaScript" runat=server&#062;<BR>&#039;create a function that generates 1 or -1<BR>function sRandom() {<BR> return ((Math.random()&#062;=0.5) ? 1 : -1);<BR>}<BR><BR> function SortVBArray(arrVBArray) {<BR>&#039;use the random function to override the default sort method of <BR>&#039;the sort property<BR> return arrVBArray.toArray().sort(sRandom).join(&#039;&#0 39;);<BR>}<BR><BR>&#060;/script&#062;<BR><BR>&#060;%<BR>&#039;create a function to call the randomiser<BR>Function SortArray(arrInput)<BR>SortArray = Split(SortVBArray(arrInput), Chr(8))<BR>End Function<BR><BR>&#039;then to actually sort it<BR>VBarray = SortArray(VBarray)<BR>%&#062;<BR><BR>HTH make it a bit clearer!<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts