PHP srand() Function

In this chapter you will learn:

  1. Definition for PHP srand() Function
  2. Syntax for PHP srand() Function
  3. Parameter for PHP srand() Function
  4. Return for PHP srand() Function
  5. Example - Seed the random number generator

Definition

The srand() function seeds the random number generator (rand()).

Syntax

PHP srand() Function has the following syntax.

srand(seed);

Parameter

Parameter Description
seed Optional. Specifies the seed value

Return

None

Example

Seed the random number generator:


<?php
srand(mktime());
echo(rand());
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP tan() Function
  2. Syntax for PHP tan() Function
  3. Parameter for PHP tan() Function
  4. Return for PHP tan() Function
  5. Example - Return the tangent of different numbers