bhimshi
bhimshi

Reputation: 1

Generate random number and string after submition of form

I create application win forms, where after submit the all detail generates random number and string. after generating random number then save it in SQL database. so tell me how to generate combination of random number and random string.

Upvotes: 0

Views: 640

Answers (4)

TechDo
TechDo

Reputation: 18649

Use DateTime.Now.Ticks.ToString() or DateTime.Now.ToFileTime().ToString() to generate random number.

Upvotes: 0

dev009
dev009

Reputation: 765

why not use session id instead of generating randoms

Upvotes: 0

GeorgesD
GeorgesD

Reputation: 1082

Here

using System;
using System.Text;

public string RandomString (Random r, int len)
{
    string str
         = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    StringBuilder sb = new StringBuilder();

    while ((len--)> 0)
        sb.Append(str[(int)(r.NextDouble() * str.Length)]);

    return sb.ToString();
}

Upvotes: 0

Habib
Habib

Reputation: 223282

Instead of generating random number and a string, you should use GUID. That will be unique as well.

string val  = Guid.NewGuid().ToString();

Upvotes: 2

Related Questions