CSharp examples for System:Random
Generates random date from minimal year to today. Default minimal date is 1990.1.1
using System.Collections.Generic; using System;// ww w .j a va 2s .co m public class Main{ /// <summary> /// Generates random date from minimal year to today. Default minimal date is 1990.1.1 /// </summary> public static DateTime GetRandomDate(int minimalYear = 1990) { DateTime startDate = new DateTime(minimalYear, 1, 1); int range = (DateTime.Today - startDate).Days; var generatedDate = startDate.AddDays(SystemRandom.Next(range)); return generatedDate; } }