SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Random number

  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    1 Post(s)
    0 Thread(s)

    Random number

    Random number

    Hello guys!

    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?
    any help?
    thank you.

                                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[1].Substring(0, 3) + " " + strresult[0].Substring(0, 3);
                                string Nr_random = RandomNumber + "-" + stroutput.Replace(" ", "").ToUpper();

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    26 Post(s)
    0 Thread(s)
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts