Jump to content

How to generate random numbers.


mani_

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??

Link to comment
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

Link to comment
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.....
Link to comment
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

Link to comment
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,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...