View Full Version : RANDOM script
Hi, I am looking for a script ( PHP )
I want script to display 5 images out of 200, these 5 imasges must be unique ( no repeating )
I think the function "array_rand" must be used but Iam not that good to write a script
Thank you
Simple. i will give it to you in c++ pseudo-code.
int[] thePictureArray = new int[200];
int[] theSelectedArray = new int[5];
/* fill thePictureArray with your pics, or if they are numberd 1 - 200 skip this step */
int select = 0;
int randomNumber = 0;
for( select = 0; select < 5; select++ )
{
boolean needNewNumber = true;
while( needNewNumber )
{
needNewNumber = false;
/* pick random number 0 - 200 */
randomNumber = random(0, 200);
/* check to see if it is used */
int check = 0;
for( check = 0; check <= select; check++ )
/* compare the number you picked with the numbers you have used */
if( randomNumber == theSelectedArray[check] )
needNewNumber = true;
}
theSelectedArray[select] = randomNumber; /* or thePictureArray[randomNumber];
}
that shoudl do it.
Extreme John
2003-09-05, 07:36 PM
Jesus Bret you make it seem as easy as washing your hands.. I expected to come in here and try and send a link to someplace... Nice!
the code may not be perfect. but i was not about to troubleshoot anything. if he can't figure it out from there. oh well. maybe read a book or something.
there are a lot faster ways to do it. but that way is the simplest to understand, i feel.
I'm impressed, that is amazing. :)
venturi
2003-09-07, 08:10 AM
If it weren't 5am and I hadn't just spent the past 20 hours rebuilding my computer I'd post the actual PHP code to accomplish exactly what s/he wants.
It's going to use the mt_srand, mt_rand and a couple other functions but is pretty simple to implement.
Lemme get a few hours of sleep and I'll post the full code up for yas. :)
My Kingdom for a pillow and a fully functional computer...
natalie
2003-09-07, 05:47 PM
Heres a quick one i did last week, its hard coded (naughty :)) and doesnt use a db but my host is a pain with not letting me do the db myself atm. But it does a random from the case, which you could adapt to use with a db. I use the variables to change the alt tag, img etc on a group of banners. Like i said it was just a quick fix.
<?php
$random = rand(0, 4);
switch ($random)
{
case 1:
$href="http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=924527-0000&PA=00000";
$imgsrc="images/rotators/460x801.jpg";
$alt="fantastic erotic ezine for women";
$mouseover="http://www.forthegirls.com/";
break;
case 2:
$href="http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=924527-0000&PA=00000";
$imgsrc="images/rotators/460x802.jpg";
$alt="fantastic erotic ezine for women";
$mouseover="http://www.forthegirls.com/";
break;
case 3: $href="http://stats.clearcard.com/servlet/Click?dec2000";
$imgsrc="images/rotators/csban2.jpg";
$alt="Couples Sex Adult Club - Foreplay On the Internet";
$mouseover="http://www.couplessex.com/";
break;
case 4: $href="http://stats.clearcard.com/servlet/Click?dec2000";
$imgsrc="images/rotators/banner1c.jpg";
$alt="Couples Sex Adult Club - Foreplay On the Internet";
$mouseover="http://www.couplessex.com/";
break;
default:
$href="http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=924527-0000&PA=499687";
$imgsrc="images/rotators/460x801.jpg";
$alt="fantastic erotic ezine for women";
$mouseover="http://www.forthegirls.com/";
break;
}
?>
And put this where you need the variables: <? echo $imgsrc; ?>
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.