Jump to content

Using rand to create a 15% outcome... any ideas?


kevin993

Recommended Posts

Hi, here is my current code:

 

<?php
if(rand(0,1) == 0) {
header('Location: http://www.website.com/page1.php');
} else {
header('Location: http://www.website.com/page2.php');
}
?> 

 

The current setup allows for a 50/50 outcome. Any ideas on how I can adjust this to get a percentage? I'd like one to be 15% and the other 85%. Thanks!

same concept...a little different...posting anyways :)

<?php
  $n = rand(1,100);
  if($n <= 15){
    header('Location: http://www.website.com/page1.php');
  } else {
    header('Location: http://www.website.com/page2.php');
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.