Generates Random DateTime. - CSharp System

CSharp examples for System:Random

Description

Generates Random DateTime.

Demo Code

//  Copyright (c) 2014 IBT  All rights reserved.
using System.Text;
using System;/*from  w w  w  . j ava2s  .  c  o  m*/

public class Main{
        public static Random random = new Random();
        /// <summary>
        /// Generates an id.
        /// </summary>
        /// <returns></returns>
        public static DateTime RandomDate(int daysback)
        {
            return DateTime.UtcNow.AddDays(-(random.Next(0, daysback)));
        }
}

Related Tutorials