Advanced
View Scraps
Categories
Most Viewed
Top Rated
Add Scraps
History
Today in History
Thoughts
Welcome,
Logout
Sign In / Sign Up
Create Unique Random number in javascript
by Vinoth
[
Edit
]
2010-02-01 11:25:48
Here I write a code to create unique random numbers. When you run this code numbers array will contain unique random numbers
Here
/*
list: javascript array;
max: maximum limit for a random number
*/
function generate_unique_ran(){
numbers=new Array('0');
var array_length=10
for(j=0;j
new_numbers = unique_rand(numbers,81); //Give random position with a maximum limit of 81
numbers.push(new_numbers);
}
}
function unique_rand(list,max) {
var number = (Math.random()*parseInt(max)).toFixed(0);;//Get a random number from 0 to max
var a=0;
for(a=0;a<list.length;a++) {
if(list[a] == number) { //If number already Present
number = (Math.random()*parseInt(max)).toFixed(0);a=-1; //Get a new Number and start it again
}
}
return number;
}
Tagged in:
Javascript
2968
0
0
Previous
Next
You must
LOGIN
to add comments
Posting your comment...
Tags
Apache
Firefox Tweeks
Shortcuts
PHP
Others
CSS
Javascript
DNS
Windows
Websites
Linux
Game programming
Mysql
CVS
HTML
MS Office
JSP/Java
FTP Server
Flash
AJAX
More...
Indian Web Directory
Time Zone Converter
Web Internet Statistics
Live Chatting Online
Comments
expected, smart move:)
Already black money holders account is empty..
The money will never return
Nice sharing..
Thank you...
Good one...
Nice post...
Good sharing.....
Good...
Thanks for nice sharing...