GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php help needed. (https://gfy.com/showthread.php?t=165599)

4Pics 08-19-2003 01:19 AM

Php help needed.
 
Does someone know how you do this

I'd like to generate 10 random #'s 1 thru 100 and atleast a gap of 4 apart. None can be a duplicate of the other.

Anyone know how to do that?

Thanks

Chaldoray 08-19-2003 01:20 AM

Yes, Pay me :1orglaugh

SilverTab 08-19-2003 01:27 AM

hmm basically you just need the rand(1,100) function and you test the result with your conditions...

BlueDesignStudios 08-19-2003 01:29 AM

Quote:

Originally posted by SilverTab
hmm basically you just need the rand(1,100) function and you test the result with your conditions...
:thumbsup sounds like a good algorithm to me

Chaldoray 08-19-2003 01:30 AM

srand function go read on it at php.net

SilverTab 08-19-2003 01:31 AM

Quote:

Originally posted by BlueDesignStudios

:thumbsup sounds like a good algorithm to me

I'm lazy...it's 4am :thumbsup

I'm assuming he knows how to do while() with conditions...etc...if not then he needs someone to do the script...not some help with it..! ;-) then I could do it...but we get back to the previous point...it's 4am... i'm tired... LOL

JDog 08-19-2003 01:51 AM

Quote:

Originally posted by SilverTab


I'm lazy...it's 4am :thumbsup

I'm assuming he knows how to do while() with conditions...etc...if not then he needs someone to do the script...not some help with it..! ;-) then I could do it...but we get back to the previous point...it's 4am... i'm tired... LOL

ah, why pay someone, this script would be so easy, worth what 10 dollars...LOL...dude, he could learn the php while() command on php.net. easy to learn..

jDoG

NiteRain 08-19-2003 02:16 AM

Okay this covers your requirements, gives you 10 randomly generated numbers, at least 4 digits away from any other number it previously gave you.

$uniq=array();

function four_or_more_apart($number,$array){
$keys=array_keys($array);
for ($x=0; $x<count($keys);$x++){
if ($number-4<$keys[$x] && $number+4>$keys[$x]){
return 0;
}
}
return 1;
}

while($counter<10){
$number = rand(1,100);
if (!$uniq[$number] && four_or_more_apart($number,$uniq)){
$uniq[$number]++;
print "$number\n";
$counter++;
}
}

Kind of curious what yah need it for though...

igneus 08-19-2003 02:45 AM

my beautiful contribution

PHP Code:

<?php
    
for ($i 1$i <= 10$i++) {
        do {
            
$num rand(1100);
        } while ((
$nums[$num] != "") ||
             (
$nums[$num 4] != "") ||
             (
$nums[$num 4] != "") ||
             (
$nums[$num 3] != "") ||
             (
$nums[$num 3] != "") ||
             (
$nums[$num 2] != "") ||
             (
$nums[$num 2] != "") ||
             (
$nums[$num 1] != "") ||
             (
$nums[$num 1] != ""));

        
$nums[$num] = $num;
        echo 
$num "\n";
    }
?>


4Pics 08-19-2003 05:03 AM

I want to rotate in random sponsor galleries. I could just hardcode certain spots to be sponsors but I figured doing it random might improve my productivity? Plus new code always helps me somewhere else and I become better at php.

I appreciate the help and when I get going i'll test it out tommorow what was posted.

Thanks

check 08-19-2003 05:18 AM

try ghostdriver


All times are GMT -7. The time now is 03:46 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123