php 获取随机数的几个方式

1.直接获取从min-max的数,例如1-20:$randnum = mt_rand(1, 20);

2.在一个数组里面随机选择一个(验证码的时候需要字母、数字混合的情况)

function randUid(){
  $str = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20";//要显示的字符,可自己进行增删
  $list = explode(",", $str);
  $cmax = count($list) - 1;
  $randnum = mt_rand(0, $cmax);
  $uid = $list[$randnum];
 }

相关文章:

  • 2021-11-27
  • 2020-04-14
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-09-13
  • 2021-10-08
  • 2021-08-22
相关资源
相似解决方案