Jump to content
Sign in to follow this  
mani_

How to generate random numbers.

Recommended Posts

Okey i have a problem..let suppose i have 1 to 50 numbers..and a month contains 30 days..i want a combination of 10 unique numbers every week day(Monday) in the month.so after every 7 days 10 numbers generated automatically out of 50..is there any solution of this??

Share this post


Link to post
Share on other sites

Hi,What exactly is this for? I suspect you have some sort of "numbers of the week" thing you are trying to put on your site? It would be eisier to reply if you supplyed that info.~alzable

Share this post


Link to post
Share on other sites
Hi,What exactly is this for? I suspect you have some sort of "numbers of the week" thing you are trying to put on your site? It would be eisier to reply if you supplyed that info.~alzable

Okey i tellI have a list of articles in database.. suppose i have 50 (id = 1 to 50)Now every week i want to display 10 unique article links on my main page.....

Share this post


Link to post
Share on other sites

Hmm, this may require some java scripting as it would be very difficult to do in php. If you really need to use php you could try using date functions but to get a random 10 articles is demanding. Too much scripting for me to write at the moment but yes, it is possible and most probably someone on this forum would have some pre made scripts.~alzable

Share this post


Link to post
Share on other sites

Well here's a shot at it, we might be able to tweak this toward your application.

<?php$startTime = mktime(0, 0, 0, 1, 1, date('Y'));$now = time();$week = 7 * 24 * 60 * 60;$wkNumber = ceil(($now - $startTime)/$week);$cycle = ($wkNumber % 5);$randNumber = 0;echo "This is week number $wkNumber.<br>";echo "We are working with cycle number $cycle.<br>";function mkRand($lwrLimit, $uprLimit){  global $randNumber;  $randNumber = mt_rand($lwrLimit, $uprLimit);}switch($cycle){  case 0:    mkRand(1, 10);    break;  case 1:    mkRand(11, 20);    break;  case 2:    mkRand(21, 30);    break;  case 3:    mkRand(31, 40);    break;  default:    mkRand(41, 50);    break;    }echo "The random number is $randNumber";    ?>

Did you want to display one unique out of a group of 10?-or-Did you want to display a group of 10 at the same time on the same page?Thanks,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...