pub fn generate_random_distribution(
n: usize,
total: u128,
min: u128,
max: u128,
) -> Result<Vec<u128>>Expand description
Generate a random distribution of amounts across n recipients.
Each amount will be in the range [min, max] and all amounts will sum to exactly total.
§Algorithm
- Start everyone at the minimum amount
- Randomly distribute the remaining amount (total - n*min) across recipients
- Shuffle the final amounts to avoid bias toward earlier recipients
§Errors
Returns an error if the constraints are unsatisfiable:
n * min > total(not enough total to give everyone the minimum)n * max < total(can’t fit the total even with everyone at maximum)