NYCPHP Meetup

NYPHP.org

[nycphp-talk] generate random unique 8-digit number

Fernando Gabrieli fgabrieli at gmail.com
Tue Mar 10 07:22:27 EDT 2009


the easiest:

$isInUse = 0 ;
while ($isInUse == 0) {
 $yourNumber = rand(0,9) . rand(0,9) . rand(0,9) .... (8 times)

 /* check here if $yourNumber is already in use and save the value in
$isInUse */
}

without saving the previous you will never be sure if you have duplicates


best,
fernando


On Mon, Mar 9, 2009 at 10:56 PM, chad qian <nynj.tech at hotmail.com> wrote:

>  Hi,
> I need to generate random 8-digit numbers continuously.And no
> duplication among all those numbers.In other word,every single 8-digit
> number must be unique.How to do php programming?
>
> Thanks a lots!
>
> chad
>
> ------------------------------
> Express your personality in color! Preview and select themes for Hotmail®. See
> how.<http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme>
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090310/145a14ea/attachment.html>


More information about the talk mailing list