Generating Random Number in PHP
Generating random numbers is very important in programming. We have to use random numbers to show a random record (Image, Saying, Article etc.) on our pages. Also, we can use random numbers for everything that we can imagine. In this article, we will see easiness of generating random numbers with PHP.
Structure 1.0: This is basic statement(void function) and we don’t determine nothing like maximum or minimum limit.
Example 1.0:
Probable Output of Example 1.0:
1.1) Generating a Random Number Between Two Numbers
Structure 1.1: If we want to generate a random number between two numbers (that we determined), we should define two parameters.
Formula: MinNum <= result <= MaxNum
Example 1.1: In this using, a random number is generated between 1000 and 2000(inclusive)
1.2)Getting a Random Element from a Collection
Example 1.2: Assume that we need to get a random item from an array.
Probable Output of Example 1.2:
Let’s improve our example…
Example 1.3: This time, we going to get multiple items from an array.
Probable Output of Example 1.3:
A Little Homework For You
As you see, it is possible getting duplicate elements. So, try to make an application that gets every single element from array only once.

Recently Typed