PHP rand() Function Last Updated : 06 Dec, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to get the random number using the rand() function in PHP, along with knowing its implementation through the example. The rand() is an inbuilt function in PHP used to generate a random number ie., it can generate a random integer value in the range [min, max]. Syntax: rand();The rand() function is used to generate a random integer. To generate a random integer in some range: Syntax: rand(min,max);Parameter values: min: It is an optional parameter that specifies the lowest value that will be returned. The default value is 0.max: It is an optional parameter that specifies the highest value to be returned. The default value is getrandmax().Return value: This function will return the random integer values ranging from min to getrandmax(), including the max value. Note: If the min and max value is not specified, default is 0 and getrandmax() respectively. Example: In this example, we will use the rand() function that will return a random integer between 0 and getrandmax(). The rand(15,35) will return a random integer in the range [15,35]. PHP <?php // Generating a random number $randomNumber = rand(); print_r($randomNumber); print_r("\n"); // Generating a random number in a // Specified range. $randomNumber = rand(15,35); print_r($randomNumber); ?> Note: The output of the code may change every time it is run. So the output may not match with the specified output. Output: 1257424548 28 Comment More infoAdvertise with us Next Article PHP rand() Function S ShivamKD Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP range() Function The range() function is an inbuilt function in PHP which is used to create an array of elements of any kind such as integer, alphabets within a given range(from low to high) i.e, list's first element is considered as low and last one is considered as high. Syntax: array range(low, high, step) Parame 3 min read PHP | random_int() Function The random_int () is an inbuilt function in PHP. The main function is to generate cryptographically secure pseudo-random integers value. When unbiased results occur in critical condition, then generated cryptographic random integers are used.The different sources of randomness used in this function 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 | readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read Like