/**
 * min 最小金额
 * max 最大金额
 * total 剩余总金额
 * num 剩余总个数
 */
function lottery(min, max, total, num) {
  if (num ==1) {
    return total;
  }
  // 确定本次随机范围
  const low = (total - (num- 1)*max) < min ? min : total - (num - 1) * max;
  let  high = (total - (num - 1)*min)> max?max:total - (num-1)*min;

  const ave = total / num > 1 ? total / num : 1;
  // 调整上限,防止前面的人红包大,后面的人红包小
  if (high > 2*ave) {
    high = 2 * ave
  }
  // 生成随机数
  let ram = parseInt(Math.random() * high);
  // 防止溢出
  if (ram < low) {
    ram = low;
  }
  if (ram > high) {
    ram = high;
  }
  return ram;
}