Results 1 to 2 of 2
Thread: Random number
Dec 4, 2012, 07:09 #1
I need your help.
This is code behind of my net page (C#).
My problem is check that the random number does not exist in my table tbl_1 where is stored in the field Nr_random.
If the random number generate exist in my table I need generate new number, else register the first random number generate.
how can i do it?
Random RandomClass = new Random(); int RandomNumber = RandomClass.Next(100000000, 999999999); string vowels = "aeiou"; string name = strEMail_user; name = new string(name.Where(c => !vowels.Contains(c)).ToArray()); string strresult = name.Split('.'); string stroutput = strresult.Substring(0, 3) + " " + strresult.Substring(0, 3); string Nr_random = RandomNumber + "-" + stroutput.Replace(" ", "").ToUpper();
Dec 10, 2012, 07:21 #2
I apologize, but this was a little confusing. You mentioned checking against a db table, but don't list any db code. The wording of your question was also a bit confusing. Are you trying to generate a random number from existing values in the table, or generate a random number and then only adding it to the table if it isn't already there?
Also, may I ask: is there a reason for the special formatting you are giving the string that goes into the Nr_random field? If you are just trying to introduce some form of entropy, it might be more efficient to just use Guid.NewGuid() instead.
In any case, a little more clarification is needed.