Read 178 times | Created 2013-10-08 08:25:25 | Updated 2013-10-08 08:25:25 | | |

 

<?php
/*********************************     
FILENAME    : dist.php     
CREATE BY   : cahya dsn     
PURPOSE     : simulating distributed segmented data
CREATE DATE : 2013-10-08     
**********************************/   
// jumlah keseluruhan data
$total_data=104; 
// jumlah yang mendapat bagian
$num=5;          
// segmentasi pembagian
$segment=5;        
/*****************************/
//inisialisasi data
$data=array();
// generate random data
for($i=0;$i<$total_data;$i++)
{
  $data[]=rand(1,100);
}
// inisialisasi hasil
$result=array();
$total_count=floor($total_data/$segment);
for($i=0;$i<$total_count;$i++)
{
  if(!isset($result[$i%$num])) $result[$i%$num]='';
  for($j=0;$j<$segment;$j++)
  {
    $result[$i%$num].="[".($i*$segment+$j)."]=>".$data[$i*$segment+$j];
  }
}
// hitung jumlah data yang belum dialokasikan (jika ada)
$remainder=$total_data % $segment;
//mengalokasikan sisa data (jika ada)
for($j=0;$j<$remainder;$j++)
{
  $result[$j%$num].="[".($i*$segment+$j)."]=>".$data[$i*$segment+$j];
}
echo "<pre>";
print_r($data);
print_r($result);