in reply to Re: Random parttitions?
in thread Random partitions?
As an extension of your idea, one could just do $count steps starting from zero, and then map the result to the desired interval.
use strict; use warnings; sub parts { my ($start, $end, $count) = @_; my @steps = (0); push @steps, rand()+$steps[-1] for 1..$count; my $scale = ($end-$start)/$steps[-1]; $_ *= $scale, $_ += $start for @steps; return @steps; } my @parts = parts 0, 10, 10; print "@parts\n";
This, of course, is not able to generate skewed distributions, so less flexibility.
|
|---|