TheUnknown Posted February 8, 2008 Share Posted February 8, 2008 I need to figure out how not to make this code pop a random number ever time its exicuted I need to number only to change every 6 or 7 times it ran Any ideas? <?php $numb = rand(50,66); echo($numb); ?> Link to comment https://forums.phpfreaks.com/topic/90115-random-number/ Share on other sites More sharing options...
Aureole Posted February 8, 2008 Share Posted February 8, 2008 Could you elaborate? I don't understand the question. Link to comment https://forums.phpfreaks.com/topic/90115-random-number/#findComment-462071 Share on other sites More sharing options...
TheUnknown Posted February 8, 2008 Author Share Posted February 8, 2008 <?php $k = rand(1,25);?> then down the page it will echo <?php echo $k ; ?> a random number between 1 to 25 so every time the page loads the number will change. I would not like the number to change every time I was trying to figure out how i can get the number to only change lets say one time every 6 times the code is executed Link to comment https://forums.phpfreaks.com/topic/90115-random-number/#findComment-462080 Share on other sites More sharing options...
kenrbnsn Posted February 8, 2008 Share Posted February 8, 2008 You need to store a counter somewhere, either in a database or as a session variable. Here's an example using a session variable: <?php session_start(); $count = (isset($_SESSION['count']))?$_SESSION['count']:0; $k = ($count == 6)?rand(1.25):$_SESSION['k']; $_SESSION['count'] = $count + 1; $_SESSION['k'] = $k ?> Ken Link to comment https://forums.phpfreaks.com/topic/90115-random-number/#findComment-462106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.