Home > php教程 > PHP源码 > body text

php mt_rand与rand函数区别与实例

WBOY
Release: 2016-06-08 17:29:49
Original
1096 people have browsed it

关于这两个函数他们有一个区别就是mt_rand效率要高到rand哦。

<script>ec(2);</script>

mt_rand与rand函数区别与实例
下面我们来看看mt_rand函数的实例吧。

function roll () {
  return mt_rand(1,6);
  }
  echo roll();

function roll ($sides) {
  return mt_rand(1,$sides);
  }
  echo roll(6); // roll a six-sided die
  echo roll(10); // roll a ten-sided die
  echo roll(20); // roll a twenty-sided die
再看一个rand函数的实例吧。

function cn111 () {
  return rand(1,6);
  }
  echo cn111();

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!