thx to both of you. i know i always do things complicated...

so if i do what you suggested, cricket:

public function getNewNumber()
{
        do
        {
                $new_number = rand(10,100000);
        }
        while ($this->_testNewNumber($new_number));

        return $new_number;

}

i'm having an endless loop :(

how would my function look like, that is checking for existence? cant
believe i am having so much trouble with this....

On 12 Aug., 03:35, cricket <zijn.digi...@gmail.com> wrote:
> On Wed, Aug 11, 2010 at 4:45 PM, McBuck DGAF <mcbuckd...@gmail.com> wrote:
> > This whole process strikes me as very inefficient.  There is no
> > mechanism to prevent your do-while loop from checking the same value
> > an infinite number of times (unless you log each random value and
> > check the next random value against the log AND the db).
>
> > I don't know what the purpose of the random value is in your app, but
> > I would suggest an entirely different approach.  If you need random
> > values in the range of "min" through "max," you could generate a table
> > ahead of time consisting of the fields id and random_number, with max-
> > min+1 rows.  (There are many random number generator sites available,
> > and you might be able to access one of their APIs as needed.)
>
> > It seems to me that it would be easier to generate these unique values
> > in some random order ahead of time, and then just associate the
> > random_numbers table with your current table through a 1-1
> > relationship.  This process would make it easy to identify the next
> > random number to be assigned, and when the random numbers have been
> > exhausted.
>
> > Just a thought.
>
> What McBuck said. I've given you a solution but you're implementing it
> in a very strange way. FWIW, this:
>
> while ($eyed = $this->Linkable->validateEyed($lkbl_eyed) ==
> "taken");
>
> is always going to return true. Why are you assigning a value to
> $eyed, which is never used, in any case? That assignment is what is
> screwing things up.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to