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
class Numeric def n_rands(n) raw = (1..n).map { |x| rand } raw.map { |x| x * to_f / raw.sum.to_f }.map { |x| x.to_i }.tap do |scaled| scaled[-1] = self - scaled[0..-2].sum end end end puts 1000.n_rands(10).inspect # [22, 70, 180, 192, 4, 121, 102, 179, 118, 12]