|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Random script
Hello,
Generally, I'll describe what was my idea at first. I've been trying to make a script for my school (football, 1vs1) that will make me random teams selection. The main idea about it, I got 11 teams, The random I was trying to do: Each team should play 20 games in a season, with each team playing each other TWICE at a season. I've tried to make this using a 'FOR' loops but I've got double games and alot of mess. Here's my try: PHP Code:
I've spent alot of time trying to make it work and failed ![]() I hope someone around will be able helping me! Thanks in advnace. |
|
#2
|
|||
|
|||
|
you may want to look at the rand function it is used to generate a random value: http://uk.php.net/manual/en/function.rand.php
|
|
#3
|
|||
|
|||
|
Try to reply to the subject..
Reading the thread itself and not the title. It might help.. Thanks anyway. |
|
#4
|
||||
|
||||
|
Tossing smart aleck remarks at people trying to help you is no way to get further help, Delusion.
What does your current code output? Have you considered using arrays? Maybe something along the lines of this pseudocode: PHP Code:
I haven't tested that, but it makes sense to me. You're looping through your teams to add two matchups per team to the $games array. Then you're looping through the $games array and printing random matchups where the current random matchup hasn't been chosen yet. This has the added advantage of being portable and of facilitating naming rather than numbering of teams. If you add team names or numbers to the one array, everything else expands automatically to accommodate it without hard-coding of counts, etc. |
|
#5
|
||||
|
||||
|
Update: I went back and tested the code after the fact, and it works like a charm.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Random script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|