Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to generate random unique id in c#

public Random a = new Random(); // replace from new Random(DateTime.Now.Ticks.GetHashCode());
                                // Since similar code is done in default constructor internally
public List<int> randomList = new List<int>();
int MyNumber = 0;
private void NewNumber()
{
  	MyNumber = a.Next(0, 10);
  	while(randomList.Contains(MyNumber))
    	MyNumber = a.Next(0, 10);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #generate #random #unique #id
ADD COMMENT
Topic
Name
4+7 =