I'm querying a list of objects.
Some of those objects have a propertie startTime which may have null values.
For those cases i want to generate a random number. For other cases I want to get the different between current time and the respective Item StartTime
var data = List.Select(e => new myCustomItem
{
Item = e,
TimeDistance = (e.StartTime.HasValue ? (e.StartTime.Value - DateTime.Now).TotalMinutes : RandomNumber(-5000, 5000))
})
.OrderBy(e => e.TimeDistance)
.ToList();
This is the function that should be called at every results that has a null value.
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
The problem is that all the results are reciving the same value.
For others that have a startDate assigned (not null) it is performing the calc.