For example: Rand (1,200);
What kind of random number is produced?
-------------------------------------------------- -------------
$ arr = array ();
While (count ($ arr) <10) {
$ a = rand (1,200);
IF (! in_Array ($ A, $ ARR)) {
$ arr [] = $ a;
}
}
Echo '
';Print_r ($ ARR);
?>
-------------------------------------------------- -------------
Since it is called the random number, of course, it is of course the same. What is the same?
If the program is used, it is not called the random number, and after 1 to 200, it is still repeated. If you are a number of 1 to 200 specified, you can write it.
Function Checkrand ($ k, $ randnum, $ i) // custom function, determine if the random number is repeated
{
For ($ j = 0; $ j <= $ i; $ j )
{
IF ($ RANDUM [$ I] == $ K)
{
Return (False);
}
}
Return (TRUE);
}
For ($ I = 0; $ I <20; $ I ) // Generate 20 cases
{
$ RANDNUM [$ I] = 0; // Initialization
}
$ I = 0;
While (True)
{
$ K = Rand (1,200);
IF Checkrand ($ K, $ RANDNUM, $ I) / / value does not repeat
{
$ i ;
$ RANDNUM [$ I] = $ K;
IF ($ i = 20)
{
EXIT (); // Take the desired random number, exit the cycle
}
}
}
$ RANDNUM [] is to satisfy the random number you want.