Randomizing my content

Hi,
I was working with randomizing a content from 4 contents in my database table. I have used ‘rand()’ function from the php library. Now my client is complaining that this randomization not affecting properly. Now my question is that does the rand function not so effecting since the no of content is very few(only 4 here)? Is this randomization using the rand() is going to be more effective when no of contents increases?
Thanks in advance.

rand() is plenty random

Your friend probably expects not to see the same content many times upon refreshing his site, but that would be unlikely – randomness generates lots of short-term streaks, not rotating, perfectly even distributions.

Thanks a lot Dan. So what do you think is could be a better way to randomize the contents? Thanks again.

There isn’t a better way to randomize content (well, mt_rand is faster, but that’s not your issue).

Maybe your client doesn’t want random content at all, but wants a cycle. Show item #1, then #2, then #3, then #4, then #1, then #2, then #3… etc. You can do that by adding a counter to each row, always selecting the row with the minimum count, and increasing the count by 1 each time the item is displayed.

Excellent Dan… Client is accepted the cycle the way you have suggested… Thanks.

Hi Dan,
Can you be able to explain a bit more about the addition of counter to each row for the contents?

It is an integer column that begins at 0. You add 1 to a row when you display it on your page. You select the row with the minimum value in this column (ORDER BY counter ASC LIMIT 1) to choose the next row to display. This ensures even distribution among the rows.

Absolutely brilliant Dan. That is the reason why I like SitePoint Forums most.