Location: PHPKode > scripts > Random Lib > random-lib/example.php
<?php
  $timeparts = explode(' ',microtime());
  $starttime = $timeparts[1].substr($timeparts[0],1);
	include ('class.random.php');
	$random = new random;
	$random->add('this have weight 1000, ', 1000);
	$random->add('this have weight 1, ', 1);
	$random->add('this have weight 200, ', 200);
	$random->add('this have weight 500, ', 500);
?>
The random items:<br />
one weights 1000, one weights 1, one weights 200, one weights 500<br />
Result for randomly select 1 item:<?=$random->select()?><br />
Result for randomly select 3 item:<? print_r($random->select(3))?><br />
Result for randomly select 3 unique item:<? print_r($random->select_unique(3))?><br />
Result for weighted randomly select 1 item:<?=$random->select_weighted()?><br />
Result for weighted randomly select 3 item:<? print_r($random->select_weighted(3))?><br />
Result for weighted randomly select 3 unique item:<? print_r($random->select_weighted_unique(3))?><br />
<?php
	  $timeparts = explode(' ',microtime());
  $endtime = $timeparts[1].substr($timeparts[0],1);
  echo 'time spent',bcsub($endtime,$starttime,6);
?>
Return current item: Random Lib