codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » Javascript » Article

Javascript Unique Random Number Generator

Article by: Premshree Pillai (8/6/2002)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: This JavaScript picks up a number of unique random elements from an array.
Viewed: 34152 times Rating (5 votes): 
 4.2 out of 5
 Rate this Article  Read Comments  Post Comments


This JavaScript picks 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] will not be picked again.

If you want to pick 4 numbers, call the function like this : pickNums(4)



Select All Code








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'Javascript Unique Random Number Generator'
Posted by :  Archive Import (Rob) at 18:07 on Wednesday, February 19, 2003
Excellent code!
Posted by :  Archive Import (Sas) at 09:47 on Thursday, April 17, 2003
Nice Code, But could you explain as how I can take this compare this value with a value in the html form.
Posted by :  Kev1 at 05:14 on Monday, December 29, 2008
This codes works so nice!!!!!!!!!
But one more thing pls,
How do i validate the number generated by this codes?

For example let say i generated a number like: 1 | 4 | 0 | 5 | 8 | 3 | 9 |
from this Code and am using it as a receipt number, how do validate it at the front end without checking it against a recordset in the database.

Thank You.
Hope to hear from you soonest.


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
Javascript - Enable and Disable form elements
by Jeff Anderson
This is a relatively little known and under-used feature of javascript which can be very useful in guiding a user through a form. Using the disabled tag, you can switch on and off elements in a form.
Check IsNumeric Function
by Jeff Anderson
A javascript validation function to check whether the details entered by a user are numeric.
Javascript Onload Event
by Jeff Anderson
Sometimes you need to perform an action immediatley after the page has loaded. That's when the onLoad Event Handler comes in handy
Form Validation Function
by Jeff Anderson
A javascript validation function that you can use to validate all types of forms.
JavaScript Field Is Empty Form Validation
by Jeff Anderson
This javascript function allows you to check whether a form field has been completed or not.
Javascript Get Selected Text
by Jeff Anderson
A cross-browser script to get text selected by the user
Check Email Validation Function
by Jeff Anderson
A javascript validation function to check whether the user has entered a valid email address in a form.
Javascript OnMouseDown
by Jeff Anderson
The javascript event handler that is called when you click the mouse button.
Validate Form and Disable Submit Button
by Marylou Marks
I have a form that validates info, but I also want to disable the submit button. The disable part worked before adding the form validating.
Multiple submit buttons on a single form
by Kiran Pai
This script shows you how to submit the contents of a form to different programs depending on which Submit button you press. Additionally it also shows how to call two different functions when you press the Submit button.








Recent Forum Threads
• Regular Expression Query Replace -- Twice Wrongly
• Processing MS Office documents with Java
• Re: help!
• Re: Can javascript preload swf files?
• ADODB.Recordset error (0x800A0CB3)
• Need Your Inputs About Level Editor Interface
• `section` is an unexpected token. Expecting white space. Line 1, position 137.
• Javascript rollover toggle help please!
• help monitoting cpu load on windows machine


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009