Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-19-2003, 01:19 AM   #1
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
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
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:20 AM   #2
Chaldoray
Confirmed User
 
Join Date: Jul 2003
Posts: 2,868
Yes, Pay me
Chaldoray is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:27 AM   #3
SilverTab
Confirmed User
 
Join Date: Nov 2001
Location: MTL
Posts: 5,060
hmm basically you just need the rand(1,100) function and you test the result with your conditions...
__________________
mmm my sig was too big... no more cool animation
but hey still! need php? ICQ: 94586959
SilverTab is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:29 AM   #4
BlueDesignStudios
Confirmed User
 
Industry Role:
Join Date: Feb 2003
Location: Australia
Posts: 9,492
Quote:
Originally posted by SilverTab
hmm basically you just need the rand(1,100) function and you test the result with your conditions...
sounds like a good algorithm to me
__________________

Blue Design Studios - Adult Design Specialists!
Email me for a free quote: [email protected]
BlueDesignStudios is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:30 AM   #5
Chaldoray
Confirmed User
 
Join Date: Jul 2003
Posts: 2,868
srand function go read on it at php.net
Chaldoray is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:31 AM   #6
SilverTab
Confirmed User
 
Join Date: Nov 2001
Location: MTL
Posts: 5,060
Quote:
Originally posted by BlueDesignStudios

sounds like a good algorithm to me
I'm lazy...it's 4am

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
__________________
mmm my sig was too big... no more cool animation
but hey still! need php? ICQ: 94586959

Last edited by SilverTab; 08-19-2003 at 01:36 AM..
SilverTab is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 01:51 AM   #7
JDog
Confirmed User
 
Join Date: Feb 2003
Location: Canby, OR
Posts: 7,453
Quote:
Originally posted by SilverTab


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

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
__________________
NSCash now powering ReelProfits.com
ALSO FEATURING: NSCash.com :: SoloDollars.com :: ReelProfits.com :: BiminiBucks.com :: VOD
PROGRAMS COMING SOON: Greedy Bucks :: Vengeance Cash
NOW OFFERING OVER 60 SITES
CONTACT :: JAMES SMITH :: CHIEF TECHNOLOGY OFFICER :: ICQ (711385133)
JDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 02:16 AM   #8
NiteRain
Confirmed User
 
Join Date: Jul 2002
Location: Fort Lauderdale
Posts: 600
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...

Last edited by NiteRain; 08-19-2003 at 02:34 AM..
NiteRain is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 02:45 AM   #9
igneus
Registered User
 
Join Date: Jul 2003
Posts: 77
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";
    }
?>
__________________
icq: 201430673
igneus is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 05:03 AM   #10
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
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
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-19-2003, 05:18 AM   #11
check
Confirmed User
 
Join Date: Apr 2003
Posts: 315
try ghostdriver
check is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.