pick at random javascript code example

Example: random dob in javascript

var dob;

//set a range of years
var min = 1900;
var max = 2004;

// Math.ceil prevents the value from being 0;
var month = Math.ceil(Math.random() * 12);
var day = Math.ceil(Math.random() * 28);
var year = Math.floor(Math.random() * (max - min) + min);

//this ensures that the format will stay mm/dd/yyyy;
if(month < 10) {
	month = "0" + month;
}
if(day < 10) {
	day = "0" + day;
}
//concatenates random dob in mm/dd/yyyy format;
dob = month + "/" + day + "/" + year;

return dob;