Associate
- Joined
- 14 Oct 2006
- Posts
- 761
is there a script were i can randomise football teams or what ever by the click of a button or everytime the page is refreshed 

breamy1990 said:is there a script were i can randomise football teams or what ever by the click of a button or everytime the page is refreshed![]()
Spuds said:Personally I'd stick every team in an array and use a random number generator to pick which element of the array is choosen. Might want to make the array 2 dimensional so you can lock each element once they have been choosen
String[] Teams = {"rotherham", "sheffield", "manchester", "chelsea", "liverpool"}
Random generator = new Random();
int randomTeam = generator.nextInt(Teams.length);
System.out.print("Selected team: " + Teams[randomTeam]);
Spuds said:Depends on what language your using, in java I'd do something like this:
Code:String[] Teams = {"rotherham", "sheffield", "manchester", "chelsea", "liverpool"} Random generator = new Random(); int randomTeam = generator.nextInt(Teams.length); System.out.print("Selected team: " + Teams[randomTeam]);
<html>
<script language="JavaScript">
<!--
team = new Array
team[1]="liverpool"
team[2]="manchester utd"
team[3]="arsenal"
team[4]="middlesborough"
team[5]="chelsea"
team[6]="cheltenham town"
team[7]="watford"
team[8]="reading"
team[9]="barcelona"
random_num = (Math.round((Math.random()*8)+1))
document.write(team[random_num]);
-->
</script>
</body>
</html>
marc2003 said:here you go. i googled a bit of javascript which will do the job. copy/paste this into notepad and save as test.html
open it in a browser and hit the refresh button.
Code:<html> <script language="JavaScript"> <!-- team = new Array team[1]="liverpool" team[2]="manchester utd" team[3]="arsenal" team[4]="middlesborough" team[5]="chelsea" team[6]="cheltenham town" team[7]="watford" team[8]="reading" team[9]="barcelona" random_num = (Math.round((Math.random()*8)+1)) document.write(team[random_num]); --> </script> </body> </html>