Q:

Autogenerated number with the use of date and time c#

Having trouble on how am i going to autogenerate a number with the use of date and time. For example, i need to generate this kind of number, 16-9685 with, 16 = year and 9685 be randomized and will be shown in a textbox. i tried this one but unfortunately, this doesn't work. thanks for helping
var random = new Random(System.DateTime.Now.Year);
int randomNumber = random.Next(-1000, -1);
TextBoxSESID.Text = randomNumber.ToString();

A:

// Keep this _r as a member, not local
Random _r = new Random();
...

// Gen a random number
int rand = _r.Next(1, 10000);

// Get the "2016-" prefix
string yearPrefix = DateTime.Now.Year + "-";

// Remove the first 2 digits of the year prefix, now it is "16-"
yearPrefix = yearPrefix.Substring(2);

// Put the year prefix together with the random number into the textbox
TextBoxSESID.Text = yearPrefix + rand;

