A Quick Question - Javascript
Hello everyone, Using _javascript_, I want to display numbers from 1 to 5 such that numbers are ordered randomly on each page refresh and none of the number is repeated. e.g first refresh 1,3,4,2,5 second refesh 2,3,5,1,2 etc etc Any help is appreciated. Thanks [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: A Quick Question - Javascript
Hello everyone, Using _javascript_, I want to display numbers from 1 to 5 such that numbers are ordered randomly on each page refresh and none of the number is repeated. e.g first refresh 1,3,4,2,5 second refesh 2,3,5,1,2 etc etc Any help is appreciated. Thanks How about something like this? script language=_javascript_ function writeNumbers() { var usedList = ; var myList = ; while (usedList.length 5) { var tempInt = Math.round(Math.random()*4) + 1; if (usedList.indexOf(tempInt) == -1) { usedList = usedList + tempInt; myList = myList + tempInt + ,; } } document.write(myList); } /script You can make some changes as to put your commas in, etc. - Jason [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: A Quick Question - Javascript
?xml version=1.0 encoding=iso-8859-1? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head titleUntitled/title meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 / /head body script type=text/_javascript_ var numArray = new Array(1,2,3,4,5); var position; var randList = ; while (numArray.length) { position = getRandomNum(0, numArray.length); temp = numArray.splice(position,1); randList += temp; if (numArray.length) randList += , // add comma } function getRandomNum(lbound, ubound) { return (Math.floor(Math.random() * (ubound - lbound)) + lbound); } document.write(randList: + randList); /script /body /html -- Charlie Griefer Marta was watching the football game with me when she said, You know, most of these sports are based on the idea of one group protecting its territory from invasion by another group. Yeah, I said, trying not to laugh. Girls are funny. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: A Quick Question - Javascript
Thanks Charlie that worked perfectly - Original Message - From: Charlie Griefer [EMAIL PROTECTED] Date: Wed, 25 Aug 2004 13:14:14 -0700 Subject: Re: A Quick Question - _javascript_ To: CF-Talk [EMAIL PROTECTED] ?xml version=1.0 encoding=iso-8859-1? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head titleUntitled/title meta http-equiv=Content-Type content=text/html;charset=iso-8859-1 / /head body script type=text/_javascript_ var numArray = new Array(1,2,3,4,5); var position; var randList = ; while (numArray.length) { position = getRandomNum(0, numArray.length); temp = numArray.splice(position,1); randList += temp; if (numArray.length) randList += , // add comma } function getRandomNum(lbound, ubound) { return (Math.floor(Math.random() * (ubound - lbound)) + lbound); } document.write(randList: + randList); /script /body /html -- Charlie Griefer Marta was watching the football game with me when she said, You know, most of these sports are based on the idea of one group protecting its territory from invasion by another group. Yeah, I said, trying not to laugh. Girls are funny. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]