Hi ,
I am facing a problem in using recursion.
I am creating random number of 6 digit for some purpose.
The check I have to made is that the generated random number should be of 6 digit,if it is greater than 6 then I have wrote logic for making it to 6 digit but the problem arises when number is less than 6.
In that case there can be two scenarios:

1) I recall that random generator function again
2) I convert the less digit number say 4 to 6 digit with some logic

In second case there is over head of writing logic,how to add extra digit.

So I prefer first case, but there was a problem.
I have implement a logic that if generated no is < 100000, then call the function again.

The problem arises when calling recursive function the new generated is less than 6 digit and so on.Due to this stack size is increasing and over head increase to excecute the statement which are useless.

But with time the probabilty is 8 : 20000 i.e in 20000 iteration , there are 8 cases when no. generated is less than 6.

I have two questions:
1) Is this the correct approach ?
2)If yes,then is there a way where I can skip stack over head.
3) If no, then what's the correct approach.

Please consider that the function and seed used in generating is OS specific.
The normal random generated no.s are usually 9-10 digit but in some cases, it is gving less than 6 digit.plz ask free for queries.

In laymen language the code is:

Code:
seedGenrator( seed );
long ran =genrateRandom(seed); // seed is clock time with pico seconds
This code is platform specific so please consider only logical portion.

Thanks
Bargi