Php help needed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 4Pics
    Confirmed User
    • Dec 2001
    • 7952

    #1

    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
    Confirmed User
    • Jul 2003
    • 2868

    #2
    Yes, Pay me

    Comment

    • SilverTab
      Confirmed User
      • Nov 2001
      • 5060

      #3
      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

      Comment

      • BlueDesignStudios
        Confirmed User
        • Feb 2003
        • 9492

        #4
        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]

        Comment

        • Chaldoray
          Confirmed User
          • Jul 2003
          • 2868

          #5
          srand function go read on it at php.net

          Comment

          • SilverTab
            Confirmed User
            • Nov 2001
            • 5060

            #6
            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
            Last edited by SilverTab; 08-19-2003, 12:36 AM.
            mmm my sig was too big... no more cool animation
            but hey still! need php? ICQ: 94586959

            Comment

            • JDog
              Confirmed User
              • Feb 2003
              • 7453

              #7
              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)

              Comment

              • NiteRain
                Confirmed User
                • Jul 2002
                • 600

                #8
                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, 01:34 AM.
                AIM: PerlScriptor

                Comment

                • igneus
                  Registered User
                  • Jul 2003
                  • 77

                  #9
                  my beautiful contribution

                  PHP Code:
                  <?php
                      for ($i = 1; $i <= 10; $i++) {
                          do {
                              $num = rand(1, 100);
                          } 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

                  Comment

                  • 4Pics
                    Confirmed User
                    • Dec 2001
                    • 7952

                    #10
                    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

                    Comment

                    • check
                      Confirmed User
                      • Apr 2003
                      • 315

                      #11
                      try ghostdriver

                      Comment

                      Working...