top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How rand() function works in php?

0 votes
668 views
How rand() function works in php?
posted Jun 19, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

0 votes

This function used to generate random number.
Please get below example:

<!DOCTYPE html>
<html>
<body>

<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>

</body>
</html>

Output:

34444
45666
38
answer Jun 19, 2014 by Amit Kumar Pandey
0 votes

rand is used to get the random number in PHP.

Syntax

int rand ( void )
int rand ( int $min , int $max )  // a random number between min and max (inclusive)

But I would suggest to try my_rand, mt_rand uses the Mersenne Twister algorithm, which is far better than the LCG typically used by rand. For example, the period of an LCG is a measly 2^32, whereas the period of mt_rand is 2^19937 − 1. Speed of mt_rand is also better then rand (syntax is same).

answer Jun 19, 2014 by Salil Agrawal
0 votes

It is used to generate random numbers.If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.

answer Jun 20, 2014 by Mohit Sharma
Similar Questions
0 votes

If I am using an editor such as Eclipse to analyze a large PHP system and I want to find the file that a function is declared in then I can search for it. I think that the (right-click) context menu for the function sometimes has an item to open the declaration but that does not always work. The same for an include statement; even if I don't know what the path will be during execution and even if the source is in multiple folders, I can search for the file. For large systems however all that can take time (my time).

Is there a tool that can process thousands (at least a couple thousand) files and produce data of what file that a called function exists in and where a function is called from? In other words, caller/called data. I understand the technical challenges. In PHP includes are processed during execution so I know it might not be possible but I am asking if there is anything that can do it as much as possible.

...