Jump to content

random


chriscloyd

Recommended Posts

$team['1'] = "team 1";
$team['2'] = "team 2";
$how_many_teams = 8;
$i = "0";
foreach($team as $team2)
{
for($team3 = $team2; $i =0; $i >= $how_many_teams; $i++)
{
$rand_team = rand(1,80);
echo $team3." with team";
}
}

umm didn't really get what you meant but try this

Link to comment
https://forums.phpfreaks.com/topic/44386-random/#findComment-215553
Share on other sites

make an array containing all 80 teams, then do a foreach loop that will do a random 8 different times.

Everytime it finds a match, add it to a new array, check to make sure it isn't already in that array by using

in_array(). if its not append it to the end of the array. If it is in the array, make another search of the original

array. Keep doing this until you have run through the list 80 times.

Link to comment
https://forums.phpfreaks.com/topic/44386-random/#findComment-215627
Share on other sites

I believe the follow code does what you want:

<?php
$teams = range(1,80);
$selections = array();
for($j=0;$j<80;$j++) {
$tmp = array();
for($i=1;$i<9;$i++) {
	$tst = $teams[array_rand($teams)];
	while($tst != $teams[$j] && in_array($tst,$tmp)) $tst = $teams[array_rand($teams)];
	$tmp[$i] = $tst;
}
sort($tmp);
$selections[$j] = implode(',',$tmp);
}
echo '<pre>' . print_r($selections,true) . '</pre>';
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/44386-random/#findComment-215630
Share on other sites

<?php
//I didn't want to make any array... So i made it with a for loop.
//It uses numbers.
$array = array();
for($i = 1; $i < 81; $i++){
array_push($array, "$i");
}

foreach($array as $val){
$rand = array_rand($array, ;
echo $val. ' > '. $rand[0].'<br>';
echo $val. ' > '. $rand[1].'<br>';
echo $val. ' > '. $rand[2].'<br>';
echo $val. ' > '. $rand[3].'<br>';
echo $val. ' > '. $rand[4].'<br>';
echo $val. ' > '. $rand[5].'<br>';
echo $val. ' > '. $rand[6].'<br>';
echo $val. ' > '. $rand[7].'<br>';
}

?>

Example: http://tzfiles.com/testing/match.php

Link to comment
https://forums.phpfreaks.com/topic/44386-random/#findComment-215632
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.