Question: I implemented the below RandomDate, but I always keep getting values closed to "From" date, i probably miss something here....

```
public static DateTime GetRandomDate(DateTime from, DateTime to)
    {
        var range = new TimeSpan(to.Ticks - from.Ticks);

        var rnd = new Random();

        var randTimeSpan = new TimeSpan((long)(range.TotalSeconds - rnd.Next(0, (int)range.TotalSeconds))); 

        return from + randTimeSpan;
    }

```

Answer: 
The problem is that:

```
var randTimeSpan = new TimeSpan((long)(range.TotalSeconds - rnd.Next(0, (int)range.TotalSeconds)));

```

is creating a TimeSpan from TICKS, not from SECONDS.

You need:

```
var randTimeSpan = TimeSpan.FromSeconds((long)(range.TotalSeconds - rnd.Next(0, (int)range.TotalSeconds)));

```

(Please check the cast too - it needs to be a double passed to FromSeconds)
My idea is we just need some random number of ticks added to start datetime to get a random date in between start and end. So my solution does not create any `TimeSpan` objects.

```
private static readonly Random random = new Random ();
private static readonly object syncLock = new object ();

public static DateTime RandomDate(DateTime from, DateTime to)
{
    lock ( syncLock )
    {
         return from.AddTicks ((long) ( random.NextDouble () * ( to.Ticks - from.Ticks ) ));
    }
 }

```