Hi i wrote a code to randomly redirect to one of 10 pages, but often same pages is displayed, i got a lot of emails from users that say the same, Is there any mistake? http://www.tarovartai.lt/konsultacija/kortos/

yes and no. Randomness does not necessarily mean that you cannot have repetition (select the same entry consecutively /1/). To achieve that you would have to explicitly exclude the last chosen entry.

1 - the probability for two consecutive draws is 10%

Many random number generators of older libcs have dubious or unknown characteristics and are slow. The mt_rand() function is a drop-in replacement for the older rand(). It uses a random number generator with known characteristics using the Â» Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.

Edit: If youâre using PHP 7.1 or later, there is no obvious difference between rand() and mt_rand().

Because random is not the same as an exhaustive set distribution. What youâre falling for is a combined failure of Sample Size, and an understanding of Individual Tests.

Random generation will result in a uniform distribution over a large sample, because, on average, you will hit each of the random results an equal number of times.

It does NOT however mean that you wont get the same number twice.

Think of it in terms of flipping a coin. If you flip a fair coin unbiased 100,000 times, you will get approximately 50% of each result, give or take some number that will generally fall within a statistical margin. However, if you flip the coin twice and get the same result both times, youâve got 100% of that result. Is the coin biased? Is it two-sided? No. Itâs just that your luck is always 50% to get one or the other, regardless of whether the previous flip was a head or a tail. This last bit is the âindependent testâ bit. The previous result has no bearing on the next.

So, the chances of you getting one of 10 sites is always* 10%, regardless of what happened before.

By contrast, an Exhaustive Set distribution (also known as a modified Round Robin selector) will give out each address once before refreshing the list once it becomes exhausted.

*: Assuming a properly random selection and distribution algorithm.

On a side note: If you want a classic example of this misunderstanding, ask a class full of people to arrange themselves randomly around a room. What youâll find most often is that they will spread themselves out as much as possible from one another - which is not random, itâs uniformâŠ Random is where they started.

Like the others have stated, the randomisation is just the same as flipping a coin or rolling the dice, there is always a probability of seeing the same result more than once and that probability is greater as the number of unseen results decreases.

The answer may in knowing exactly the behavior you really want from this.
Perhaps you want to show each of the pages in a shuffled sequence.
Or if there is no real sequence of consecutive pages and the ârandomâ page link may be visited at any time, any number of times, you may require a cookie of some sort to record which of the ten have been seen already. Or maybe an array of the addresses they have yet to see which can be passed to your script.
It all depends upon what you want to happen.