Flex Study Notes: random sorting of array elements

Source: Internet
Author: User

Call method: randomorder (array) <br/> the function returns a new array, which is the result of the random sorting of the array. <br/> example: </P> <p> program code <br/> var myarray: array = ["A", "B", "C ", "D"] <br/> myarray = randomorder (myarray) </P> <p> program code <br/> // random array sorting <br/> function randomorder (targetarray: array ): array <br/> {<br/> var arraylength: Number = targetarray. length <br/> // create an array in the normal sequence <br/> var temparray1: array = [] <br/> for (VAR I = 0; I <arraylength; I ++) <br/>{< br/> temparray1 [I] = I <br/>}< br/> // <br/> // create a random string based on the previous number of groups. out-of-order array <br/> var temparray2: array = [] <br/> for (VAR I = 0; I <arraylength; I ++) <br/>{< br/> // randomly extract elements from the normal sequence array <br/> temparray2 [I] = temparray1.splice (math. floor (math. random () * temparray1.length), 1) <br/>}< br/> // <br/> // create a temporary array. store the data obtained from targetarray based on the previous disordered array. <br/> VaR temparray3: array = [] <br/> for (VAR I = 0; I <arraylength; I ++) <br/>{< br/> temparray3 [I] = targetarray [temparray2 [I] <br/>}< br/> // <br/> // return the final result returned array <br/> return temparray3 <br/>}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.