kevin993 Posted June 24, 2009 Share Posted June 24, 2009 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! Link to comment https://forums.phpfreaks.com/topic/163535-using-rand-to-create-a-15-outcome-any-ideas/ Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 if(rand()%100<15) { header('Location: http://www.website.com/page1.php'); } else { header('Location: http://www.website.com/page2.php'); } Link to comment https://forums.phpfreaks.com/topic/163535-using-rand-to-create-a-15-outcome-any-ideas/#findComment-862838 Share on other sites More sharing options...
rhodesa Posted June 24, 2009 Share Posted June 24, 2009 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'); } ?> Link to comment https://forums.phpfreaks.com/topic/163535-using-rand-to-create-a-15-outcome-any-ideas/#findComment-862840 Share on other sites More sharing options...
kevin993 Posted June 24, 2009 Author Share Posted June 24, 2009 thanks guys, it works! Link to comment https://forums.phpfreaks.com/topic/163535-using-rand-to-create-a-15-outcome-any-ideas/#findComment-862868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.