hello guys..can someone help me to create a function that generates random numbers composing of 9 digits with the ff limitations..

  • must not have consecutive numbers in any place...sample 158461247....1 and 2 is consecutive numbers...
  • must not have same numbers before and after....sample 155483628....5 and 5 is same number...

Hoping that anyone will help me regarding this matter.Thanks in advance...

Member Avatar for diafol

This is homework? Show us your code so far...

$numchars = rand(4,15); 
            $chars = explode(',','a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9'); 
            $random=''; 
            for($i=0; $i<$numchars;$i++)  
                { 
                  $random.=$chars[rand(0,count($chars)-1)]; 
                } 

                $unique_id=$random;

i think this will help

Member Avatar for diafol

i think this will help

I think you've tried to do the work for him :(

I think you've tried to do the work for him

Only showed him how to use rand. None of the OP requirements are met.

Member Avatar for diafol

My bad p - didn't scan it. I was hoping the OP was going to respond before he started receiving snippets. Apologies AS. :)

@diafol its ok i use this code for my work i just give him for hint

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.