Unique Random Numbers in PHP

If you would like to show random numbers using PHP you can do this:

<?php
	$min = 1;
	$max = 100;
	$total = 100;
	$arrItems = array();
	while ( count($arrItems) < $total ) {
		$item = mt_rand($min,$max);
		if (!in_array($item,$arrItems)) {
			$arrItems[] = $item;
			echo $item."<br />";
		}
	}
Tags:

Leave a Reply

Your email address will not be published.