PDA

View Full Version : how can i generate random birthdates?


lorry4
05-04-2003, 04:39 AM
i am currently creating an array of 23 people and i need to assign a random birthdate for each person. if anyone can give me an idea of the command to do this it would be a great help....Thanks

BrightNail
05-04-2003, 05:06 AM
yup..here you go...

<!-- this is the main code -->

//added functionality to find 'randomness'
var b_day=New Array('july 4, 1980','sept. 6','blah','another');
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};
function rand(number) {
return Math.ceil(rnd()*number);
};


<!-- put this where you want the randomness to happen -->

for instance:
Dean's birthday is:
<script language="javascript">
x=4; //how many elements in your b_day array
var bday=rand(x);
document.write(b_dayarray[bday]);
</script>

check this though..can't remmeber if the random also does zeros which will be needed for your first array element. If it doesn't match up..just do this...
document.write(b_dayarray[bday-1]);