1 Public stringBindcode (intlength)2 {3 stringVchar ="1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,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,p,q,r,s,t , U,v,w,x,y,z";4 5 string[] Vcarray = Vchar.split (NewChar[] {',' }); 8Random Rand =NewRandom (); Ten One intA; Alist<int> result =Newlist<int>(); - stringNumlist =string. Empty; - the for(inti =1; I < length +1; i++) - - { -A = rand. Next (1, vcarray.length);//set the range. I'm here to fetch data from the database 1~n + if(result.) Contains (a)) - { +i = i-1;//duplicate values, repeat again, cycle times minus one time A } at Else - { -Numlist + = Vcarray[a];//no duplicate values are added within the collection - } - } - in returnnumlist; -}
Call:
1 protected void Page_Load (object sender, EventArgs e)2 {3 if (! IsPostBack)4 {5 barcoded.text = Bindcode (4); 6 }7 }
Website Login Simple Verification Code