PHP srand( ) Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report Many times while designing questions or algorithms we require to generate random numbers. We already have studied a built-in function in PHP for generating random numbers in the article PHP |rand() Function. The rand() function is used to generate random numbers. If we generate a sequence of random numbers with rand() function, it will create the same sequence, again and again, every time the program runs. To solve this issue another built-in function of PHP, srand() can be used. The srand() function in PHP is used to seed the random number generator rand(). The srand() function sets the starting point for producing a series of pseudo-random integers. If srand() is not called, the rand() seed is set as if srand(1) were called at program start. The srand() function seeds the random number generator with seed(arg) or with a random value if no seed(arg) is given. Syntax: srand($seed) Parameters: This function accepts a single parameter seed. It is an optional parameter and is of integer type. It specifies the seed value. Return Value: This function does not returns any value. Examples: Input : srand(time()); Output : 1793542495 Input : srand(5) Output : 3 Below programs illustrate the srand() function in PHP: When timestamp is used as the $seed value along with srand() function: PHP <?php srand(time()); echo(rand()); ?> Output: 1793542495 When a user-defined seed value is passed as an argument with srand() function: PHP <?php srand(5); echo(rand(1, 10)); ?> Output: 3 Important Points To Note: srand() function can be used to generate random numbers. srand() function doesn\'t create the same sequence of random numbers like the rand() function. It doesn't have a return value. References: http://php.net/manual/en/function.srand.php Comment More infoAdvertise with us Next Article PHP srand( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read PHP strncmp() Function The strncmp() is an inbuilt function in PHP which is used to compare first n character of two strings. This function is case-sensitive which points that capital and small cases will be treated differently, during comparison. This function compares two strings with first n character and tells whether 2 min read PHP array_rand() Function This inbuilt function of PHP is used to fetch a random number of elements from an array. The element is a key and can return one or more than one key. On a practical basis, this is not that useful because the function uses pseudo-random number generator that is not suitable for cryptographic purpose 2 min read PHP | is_string() Function The is_string() function is an inbuilt function in PHP which is used to check whether the given value is a string or not. Syntax: bool is_string( mixed $var ) Parameters: This function accepts one parameter as mentioned above and described below: $var: It contains the value that need to check. Retur 1 min read PHP | is_real() Function The is_real() function is an inbuilt function in PHP which is used to check the given value is a real number or not. Syntax: bool is_real( mixed $var ) Parameters: This function accepts one parameter as mentioned above and described below: $var: It contains the value of variable that need to be chec 2 min read Like