|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
int k=0;
int n1; while(pkey3!=0) { n1=pkey3%10; k=k*10+n1*2; pkey3=pkey3/10; } if(k!=0) { k=k+1111; int k1=k%100; k=k/100; String k2=" "+k+"SR"+k1; ********************************************** i am doing a project in jsp n mysql. As a part of it i need to generate a unique string as in the above code say "k2". for this we r taking an input from the jsppage say "pkey3". hope u understand the logic. but the problem i am facing here is for pkey3 values like 10,100,1000,20,200,2000...... and so on the value generated for k2 is the same... it should b unique. . so i need some modifications in the code. so please help me out to correct this code or suggest me a simple algorithm to generate a unique string..... thanx in advance regards simres |
|
#2
|
||||
|
||||
|
if you want a unique number, why not use a timestamp - or a rand seeded with a microtime value.
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Backingline: Advanced betting software, dutching calculator |
|
#3
|
||
|
Varies by implementation, but something like:
srand (time (0)); (seed just once) then use rand (). can be scaled with the modulus operator. |
|
#4
|
||||
|
||||
|
Quote:
Actually, being that it's mysql, you'd define the field as and "auto increment" Here's what I use: (taken from some code of mine) Code:
create table test ( id int(6) auto_increment primary key, name varchar(50) not null, dob date ); Does it need to be a string? Does it need to be predictable from the k2?
__________________
"Science is constructed of facts as a house is of stones. But a collection of facts is no more a science than a heap of stones is a house." - Henri Poincare |
|
#5
|
|||
|
|||
|
hai all,
thanks for the response.but "k2" should be a string itself and it can,t be generated as autoincrement..... so please help in this regard. regards simres |
|
#6
|
||||
|
||||
|
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > simple algo going wrong |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|