This thread is inspired by this thread
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10242753

<?php
//	by : Jimson Chang

define('RSIZE',		7);						// size of random number
define('LOOPCOUNT',	70000);					// count of generated random number
define('SAMPELS',	40);					// samples of LOOPCOUNT generated random number
define('BPOINT',	LOOPCOUNT / RSIZE);		// middle point that break number into less than and more than
define('PERCENT',	0.05);					// percentage used for +-
define('PLUSMINUS',	PERCENT * BPOINT);		// plus minus BPOINT value that considered it to be in the middle
											// change this value according to your LOOPCOUNT value
define('LOWBPOINT',	BPOINT-PLUSMINUS);
define('HIGHBPOINT',BPOINT+PLUSMINUS);

function random_generate($a=null) {
	return rand(1, RSIZE);
}

function random_stats($rKey) {
	static $data;

switch($rKey) {
	case 'g':
		return $data;
		break;
	case 'reset':
		$data = null;
		break;
	default:
		if(!isset($data[$rKey])) {
			$data[$rKey] = 1;
		} else {
			$data[$rKey]++;
		}
}
}

function random_finalize_sampels($rKey = NULL) {
	static $dataA;
	static $holder;
	static $currentVal;
	static $currentKey;
	static $i = 1;

switch($rKey) {
	case 'g':
		return $dataA;
		break;

	case 'store':
		if(!isset($dataA[$i]['below'])) $dataA[$i]['below'] = 0;
		if(!isset($dataA[$i]['equal'])) $dataA[$i]['equal'] = 0;
		if(!isset($dataA[$i]['larger'])) $dataA[$i]['larger'] = 0;
		$dataA[$i][$holder]++;
		break;

	case 'lowhigh':
		if(!isset($dataA[$i]['low'])) {
			$dataA[$i]['low']	=	array('k' => $currentKey, 'v' => $currentVal);
		}
		if(!isset($dataA[$i]['high'])) {
			$dataA[$i]['high']	=	array('k' => $currentKey, 'v' => $currentVal);
			break;
		}
		if($currentVal > $dataA[$i]['high']['v']) {
			$dataA[$i]['high']	=	array('k' => $currentKey, 'v' => $currentVal);
		}
		if($currentVal < $dataA[$i]['low']['v']) {
			$dataA[$i]['low']	=	array('k' => $currentKey, 'v' => $currentVal);
		}
		break;

	case 'decide':
		$temp	=	random_stats('g');
					for($j=1; $j<=RSIZE; $j++) {
						$currentVal	=	$temp[$j];
						$currentKey	=	$j;
						if(($temp[$j] > LOWBPOINT) AND ($temp[$j] < HIGHBPOINT)) {
							$holder	=	'equal';
						} elseif($temp[$j] < LOWBPOINT) {
							$holder	=	'below';
						} else {
							$holder	=	'larger';
						}
						random_finalize_sampels('store');
						random_finalize_sampels('lowhigh');
					}
					$i++;
		break;

	default:
		random_finalize_sampels('decide');
		random_stats('reset');
}
}

function random_highlow(&$rData) {
	$rHigh		=	max($rData);
	$rLow		=	min($rData);
	$rData		=	array_flip($rData);
	$r['high']	=	array($rHigh, $rData[$rHigh]);
	$r['low']	=	array($rLow, $rData[$rLow]);
					return $r;
}

//	+------+
//	| main |
//	+------+
	for($i=1; $i<=SAMPELS; $i++) {
		for($j=1; $j<=LOOPCOUNT; $j++) {
			random_stats(random_generate());
		}
		random_finalize_sampels();
	}
?>
<html>
	<title>random number</title>
	<body bgcolor=#DFDFDF>
		<b>Test Environment</b>
		<table border=1 cellpadding=5 cellspacing=0>
			<tr><td>random number size</td><td><?php echo RSIZE?></td></tr>
			<tr><td>loop count</td><td><?php echo LOOPCOUNT?></td></tr>
			<tr><td>total sampels</td><td><?php echo SAMPELS?></td></tr>
			<tr><td>break point (actual) occurance in each sampels</td><td><?php echo BPOINT?></td></tr>
			<tr><td>low break point occurance in each sampels</td><td><?php echo LOWBPOINT?></td></tr>
			<tr><td>high break point occurance in each sampels</td><td><?php echo HIGHBPOINT?></td></tr>
		</table><br>
		<b>Sampel's Analysis</b><br>
		HOGRN = Highest occurance generated random number ( num => occurance )<br>
		LOGRN = Lowest occurance generated random number ( num => occurance )<br>
		TOINS = Total occurance in sampel for <?php echo RSIZE?> numbers.<br>
		<table border=1 cellpadding=5 cellspacing=0>
			<tr align=center bgcolor=#888888>
				<td>Sampel Num</td>
				<td>HOGRN</td>
				<td>LOGRN</td>
				<td>HOGRN - LOGRN</td>
				<td>TOINS < <?php echo LOWBPOINT?></td>
				<td><?php echo LOWBPOINT.' < TOINC < '.HIGHBPOINT?></td>
				<td>TOINS > <?php echo HIGHBPOINT?></td>
			</tr>
			<?php
			static $total	= array('below' => 0, 'equal' => 0, 'larger' => 0);
			static $low;
			static $high;
			$dataA	= random_finalize_sampels('g');
			for($i=1; $i<=sizeof($dataA); $i++) {
				$highKey	=	$dataA[$i]['high']['k'];
				$lowKey		=	$dataA[$i]['low']['k'];
				$highVal	=	$dataA[$i]['high']['v'];
				$lowVal		=	$dataA[$i]['low']['v'];
				$diff		=	$highVal-$lowVal;

			echo	"<tr align=center>".
						"<td>$i</td>".
						"<td>$highKey => $highVal</td>".
						"<td>$lowKey => $lowVal</td>".
						"<td>$diff</td>".
						"<td>{$dataA[$i]['below']}</td>".
						"<td>{$dataA[$i]['equal']}</td>".
						"<td>{$dataA[$i]['larger']}</td>".
					"</tr>";
					$total['below']		+= $dataA[$i]['below'];
					$total['equal']		+= $dataA[$i]['equal'];
					$total['larger']	+= $dataA[$i]['larger'];
					if(!isset($high[$highKey]))	$high[$highKey] = 0;
					if(!isset($low[$lowKey]))	$low[$lowKey] = 0;
					$high[$highKey]++;
					$low[$lowKey]++;
		}
		$high	=	random_highlow($high);
		$low	=	random_highlow($low);
		?>
		<tr align=center bgcolor=#888888>
			<td>&nbsp;</td>
			<td>
				high: <?php echo $high['high'][1].' => '.$high['high'][0].' occ' ?><br>
				low: <?php echo $high['low'][1].' =>'.$high['low'][0].' occ' ?><br>
			</td>
			<td>
				high: <?php echo $low['high'][1].' => '.$low['high'][0].' occ' ?><br>
				low: <?php echo $low['low'][1].' => '.$low['low'][0].' occ' ?><br>
			</td>
			<td>&nbsp;</td>
			<td><?php echo $total['below']?></td>
			<td><?php echo $total['equal']?></td>
			<td><?php echo $total['larger']?></td>
		</tr>
	</table>
	<br>
	<b>Summary</b><br>
	<?php

	echo	'Total generated random numbers = '.SAMPELS*LOOPCOUNT.'<br><br>'.
			'<b>NOT RANDOM</b><br>'.
			'When not random, '.SAMPELS*LOOPCOUNT.' divide by '.RSIZE.' = '.(SAMPELS*LOOPCOUNT)/RSIZE.' numbers should occures in this value.<br>
			Which means also each sampel should have '.SAMPELS*LOOPCOUNT.' divide by '.SAMPELS.' => '.(SAMPELS*LOOPCOUNT)/SAMPELS.' divide by '.RSIZE.' = '.((SAMPELS*LOOPCOUNT)/SAMPELS)/RSIZE.'
			values which are <b>SAME</b>.<br>'.
			'In not random way, each sampel should will have only 1 state which is equal, or <b>TOINS</b> = '.LOOPCOUNT/RSIZE.'<br>
			where in the total row ('.SAMPELS.' sampels), it should yield '.SAMPELS*RSIZE.' in ( TOINS = '.LOOPCOUNT/RSIZE.' ) column only. (becoz there is only one state)<br>'.
			'<br><br>'.

			'<b>WHEN WE RANDOM IT, THE RESULT SHOULD NOT BE THE SAME LIKE NOT RANDOM</b><br>'.
			'We plus minus '.PERCENT * 100 .' % to make the break point scalable a byte.<br>
			And now, we have 3 states, where < TOINS or > TOINS or equal to (+-)TOINS.<br>
			When you got (+-)'.SAMPELS*RSIZE.' in (+-)TOINS column, it is nearly <b>NOT RANDOM</b> in my point of view.';
	?>
</body>
</html>

    this are the result zipped.
    basically, there is no RANDOM
    after 7000

      this is the code if u don't like to copy and paste.

      set tab = 4

        What happens if you use mt_rand(), instead of rand() ??

        Also, I haven't had any caffiene yet this morning, what am I supposed to be looking for in the output?

        (And some (more) comments in the code would be nice -- if you were a coworker, I'd flog you.)

          Okay, i REALLY need to go get coffee....

          What is the intention of your "breakpoint", and how is it the "middle point that break number into less than and more than"??

            BPOINT = is the middle value when numbers are divide accordingly.

            let say our random generate function will give us 7 number, which is 1,2,3,4,5,6,7

            and we want to loop it for 98 times. (for better division)

            // eg. code
            for($i=1; $i<=98; $i++) {
                random_generate();
            }
            

            so, in the end, we will have 98 (random) numbers which may contained 1...7.

            if we don't random the number, basically it will be equal.(means every number will have same occurances).

            so, the equal number (when not random) = LOOPCOUNT / RSIZE
            so, 98/7, we will have 14 number of 1 to 7 (when not random)

            so, if the random function really give us random values, it will be impossible for us to get 14 numbers of equal occurances "1..7" under random.

            so, the result might be some number have less than 14 occurances, some have larger than 14 and some might maybe equal to 14 (but not all numbers "1...7").

            so the BPOINT is to let us know the 14 and we can plus minus it
            to consider the range as "equal". Okay, why we need to plus minus it.

            the reason i set BPOINT is to find out the occurances of random numbers that =>looks like equal divided unRandom numbers.

            the plus minus is to make a range of occurances that i consider the occurances are same as equal divided unRandom numbers.

            by looking the results, i found a tendancy that the occurances of random number will shift to like the value of unRandom number occurances when we generate more and more random numbers.
            using 5% (+-).

            In other words, it means, i can predict (in a more higher probabilty way) what is the next random number.

            My conclusion is, the rand() or mt_rand() don't really random number, it just random the show time of number but in the end, all numbers will have a same (+-) of occurances.

            one problem i found was, why when we do loopcount 70,000+
            we can't have the result like we do loopcount = 70?
            when their breakpoint or equal occurances percentage of range still the same?

            so, does random still exists?

            any maths expert can try to figure out for me... i will appreciate it.

            from the analysis and test i run, i am convince that there is an algorithm to check for the next random numbers. (if u still want to call it random number).

            Jimson unRandom Theory... 🙂 lol

              I've never trusted rand() for serious work anyway. Depends too much on operating system, choice of compiler and (when not being seeded manually) phase of the moon.

                Originally posted by Weedpacket
                I've never trusted rand() for serious work anyway. Depends too much on operating system, choice of compiler and (when not being seeded manually) phase of the moon.

                weed, if you are free, perhaps u can repair my
                random_generate() so that i can learn to see
                how u will do it.

                  Write a Reply...