# recursive function [closed]

I want to generate a random number then to check if it is in the database. If not then redo it.

My pseudo code:

                        PIN = GenerateRandomNumber().ToString();

// check if it is existing in the database

var listID = list_from_database
if (!listID.Contains(PIN))
// Save To database
else
{
// redo it until listID contains PIN
}

-
This should really be on StackOverflow, Code Review is for working code - see the FAQ –  Trevor Pilley Nov 9 '12 at 20:34

## closed as off topic by Glenn Rogers, Jeff Vanzella, svick, dreza, CorbinNov 11 '12 at 6:47

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I don't have the ability to transfer this to SO so I'll give my answer:

Just use a loop instead of recursion.

while(true)
{
PIN = GenerateRandomNumber().ToString();

var listID = list_from_database

if (!listID.Contains(PIN))
{
// Save To database

break;
}
}

-