Language: C#
Random Dates
static void Main(string[] args) { RandomDateGenerator generator = new RandomDateGenerator(new Random()); List<DateTime> RandomDates = new List<DateTime>(); for (int i = 0; i < 100; i++) { RandomDates.Add(generator.RandomDay()); } RandomDates.RemoveAll(x => x.Month == 2); RandomDates.ForEach(x => Console.WriteLine(x.ToLongDateString())); Console.WriteLine(RandomDates.Count); } } public class RandomDateGenerator { Random gen; public RandomDateGenerator(Random gen) { this.gen = gen; } public DateTime RandomDay() { DateTime start = new DateTime(1995, 1, 1); int range = ((TimeSpan)(DateTime.Today - start)).Days; return start.AddDays(gen.Next(range)); } }
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

