Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random page displayed by importance

Status
Not open for further replies.

Haraldo

Programmer
Jun 9, 2003
41
GB
I'd like to display a page chosen by random from several pages, but the pages need to be ranked with importance. E.g

Page1 = 50% Page2 = 30% Page3 = 20%

The percentages can change, what above shows is that Page1 is the most important and will show itself 50% of the time, Page2 30% of the time and Page3 will appear but just less frequently at 20% of the time.

Is there a function that can do this? Or will i need to create some logic.

Thanks for any support.
 
The simplest (and classic;) logic:
Get a (pseudo)random number in range 0..99 with rand(0,99).
if n < 50 - select 1st page
else if n < 80 - select 2nd page
else - select 3rd page.
Don't forget to seed the random number generator with srand (see PHP manual).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top