I have a value, say 20010. I want to randomly divide this value over 24 hours. So basically split the value into a 24 slot big array where all slots are randomly big.
Wh
Here's another solution that I think would work very well for this. Each time the method is called, it will return another set of randomly distributed values.
public static IEnumerable Split(int n, int m)
{
Random r = new Random();
int i = 0;
var dict = Enumerable.Range(1, m - 1)
.Select(x => new { Key = r.NextDouble(), Value = x })
.OrderBy(x => x.Key)
.Take(n - 2)
.Select(x => x.Value)
.Union(new[] { 0, m })
.OrderBy(x => x)
.ToDictionary(x => i++);
return dict.Skip(1).Select(x => x.Value - dict[x.Key - 1]);
}