rand

(PHP 4, PHP 5, PHP 7)

rand锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟�

说锟斤拷

rand ( void ) : int
rand ( int $min , int $max ) : int

锟斤拷锟矫伙拷锟斤拷峁╋拷锟窖★拷锟斤拷锟� min 锟斤拷 max锟斤拷rand() 锟斤拷锟斤拷 0 锟斤拷 getrandmax() 之锟斤拷锟轿憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷要 5 锟斤拷 15锟斤拷锟斤拷锟斤拷 5 锟斤拷 15锟斤拷之锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 rand(5, 15)锟斤拷

Note: 锟斤拷某些平台锟铰o拷锟斤拷锟斤拷 Windows锟斤拷getrandmax() 只锟斤拷 32767锟斤拷锟斤拷锟斤拷锟揭拷姆锟轿э拷锟斤拷锟� 32767锟斤拷锟斤拷么指锟斤拷 min 锟斤拷 max 锟斤拷锟斤拷锟酵匡拷锟斤拷锟斤拷锟缴革拷锟斤拷锟斤拷锟斤拷耍锟斤拷锟斤拷呖锟斤拷锟斤拷锟� mt_rand() 锟斤拷锟斤拷锟街拷锟�

锟斤拷锟斤拷

min

锟斤拷锟截碉拷锟斤拷锟街碉拷锟侥拷希锟�0锟斤拷

max

锟斤拷锟截碉拷锟斤拷锟街碉拷锟侥拷希锟�getrandmax()锟斤拷

锟斤拷锟斤拷值

A pseudo random value between min (or 0) and max (or getrandmax(), inclusive).

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
4.2.0锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷远锟斤拷锟斤拷胁锟斤拷帧锟�

锟斤拷锟斤拷

Example #1 rand() 锟斤拷锟斤拷

<?php
echo rand() . "\n";
echo 
rand() . "\n";

echo 
rand(515);
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

7771
22264
11

锟轿硷拷

  • srand() - 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
  • getrandmax() - 锟斤拷示锟斤拷锟斤拷锟斤拷锟斤拷目锟斤拷锟街�
  • mt_rand() - 锟斤拷锟缴革拷锟矫碉拷锟斤拷锟斤拷锟�