Random number in range [min - max] using PHP

Val picture Val · Nov 13, 2010 · Viewed 120.5k times · Source

Is there a way to generate a random number based on a min and max?

For example, if min was 1 and max 20 it should generate any number between 1 and 20, including 1 and 20?

Answer

Prisoner picture Prisoner · Nov 13, 2010
<?php
  $min=1;
  $max=20;
  echo rand($min,$max);
?>