Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    59
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to Generate Random Numbers?

    Hi guys, i have this number, 878777886XXXXXX. The Xs represent random numbers that I want to generate. I want to generate 1000 numbers that does not repeat using php. can anyone help?

    thanks!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    We can but don't expect us to just give you the code. What exactly have you tried?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this
    PHP Code:
    $arr_randoms = array();
    $i 0;
    do {
       
    $val '878777886' mt_rand(1,999999);
       if (!
    array_key_exists($val$arr_randoms)) {
           
    $arr_randoms[] = $val;
           
    $i ++;
       }
    }while(
    $i 1000); 
    would generate an array with 1000 unique, random, elements (stat start with 878777886).
    maybe there is a shorter/faster way --> who improves or comes with a more performant alternative?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •