Advertisement
Rev0verDrive

Php MT_Rand

Dec 12th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. $rand1 = 0; $rand2 = 0; $rand3 = 0; $rand4 = 0;
  4. $rands = array();
  5.  
  6. for ($x = 1; $x <= 100; $x++) {
  7.    
  8.     $rand = mt_rand(1, 4); // random chose
  9.    
  10.     // Stats - increment based on chosen random
  11.     switch ($rand) {
  12.         case '1': $rand1++; break;
  13.         case '2': $rand2++; break;
  14.         case '3': $rand3++; break;
  15.         case '4': $rand4++; break;
  16.     }
  17.    
  18.     array_push($rands, $rand); // add rand result to array
  19.    
  20. }
  21.  
  22. // echo stats
  23. echo("<pre>Total Rands: ".count($rands)."</pre>");
  24. echo("<pre>Rand1: (".$rand1.") | Rand2: (".$rand2.") | Rand3: (".$rand3.") | Rand4: (".$rand4.")</pre>");
  25.  
  26. // echo results
  27. $rand = 0;
  28. $td_cnt = 0;
  29. foreach ($rands as $r) { // loop array - build columns
  30.     $rand++; // increment
  31.     $td_cnt++; // increment
  32.     IF ($td_cnt == 1) { echo("<div style=\"width:200px; float:left;\">"); }
  33.     echo("<pre>rand(".$rand."): ".$r."</pre>");
  34.     IF ($td_cnt == 25) { echo("</div>"); $td_cnt = 0;}
  35.     IF ($rand == 100) { echo("</div><div style=\"clear:both;\"></div>"); }
  36. }
  37.  
  38. // dump array
  39. echo("<pre><strong>Array Dump</strong></br>".print_r($rands, true)."</pre>");
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement