The net's largest PHP, CGI, Perl, JavaScript and ASP script collection and resource web portal
  New Listings
New Listings
Most Popular
Most Popular
Top Rated
Top Rated
Discussion
Discussion
Link to Us!
Link To Us
Search For:         
   
 
Hotscripts :: Listing Reviews


Reviews for Listing # 17104

   Unique Random Numbers   Hits: 2658 

 
This JavaScript picks up a number of unique random elements from an array. For example; if you have an array myArray consisting of 10 elements and want to pick 5 unique random elements. Suppose initially myArray[3] is picked randomly, then myArray[3] should not be picked again. If you want to pick 4 numbers, call the function like: pickNums(4).


Version: n/a   Platform(s): n/a   Updated: Tue Jun 24 2003

Listing Details
Refer
PDF
  Member Reviews (1) Visitor Ratings


Very long winded code., Apr 17, 2006 Reviewed By: felgall
Review Of: Unique Random Numbers in JavaScript :: Randomizing :: Combination
An extremely long way around way to do it when sorting the array into random order and then reading the resultant entries sequentially can be done in two lines of code. myArray = new Array('1','2','3','4','5' ,'6'); // code to randomize array follows function randOrd(){return (Math.round(Math.random() )-0.5); } myArray.sort( randOrd ); // and from here you just read as many random selections you want from the front of the array.




Register | FAQ/Support | Contact Us | About Us | Getting Rated | Link to Us | Bookmark Us | Advertising Info | Terms of Use | Privacy Policy
Copyright © 2008 iNET Interactive. All rights reserved.
Other iNET Interactive Sites:
Web Hosting Talk | dBForums | Mac Forums | Hosting Catalog