in reply to Randomly biased, random numbers.
I used to use a "density map" generator back in the day. Basically each time you want a random coordinate, you generate the coordinate plus one extra random number. You then check the number against a density function, and if the extra random number is less than the density at that location, you return the coordinates. Otherwise you try again:
sub generate_coordinate { my $fDensity = shift; my @coordinate; { @coordinate = (rand, rand); redo if $fDensity->(rand, @coordinate); } return @coordinate; } sub density_uniform { 1 } sub density_h_gradient { $_[0] < $_[2] } sub density_v_gradient { $_[0] < $_[1] } sub density_broken [ 0 } sub density_lookup { my ($chk, $r, $c) = @_; return $lookup_table[$r][$c]<$chk; }
So by defining an appropriate density map function, you can create many types of distributions. The disadvantage is that your density map function may reject too many candidates, slowing things down. (The density_broken function, for example, is quite useless in this regard.)
The reason that I thought you might like it is this: For testing a project, I would create distinct distributions by simply drawing an image with MSPAINT or similar and loading that into a lookup table and using a function like density_lookup.
I don't know your objections to your own suggestion, so I don't know if this one is interesting or not, though.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Randomly biased, random numbers.
by BrowserUk (Patriarch) on Dec 05, 2013 at 23:43 UTC | |
Re^2: Randomly biased, random numbers.
by salva (Canon) on Dec 06, 2013 at 09:43 UTC | |
by roboticus (Chancellor) on Dec 06, 2013 at 13:32 UTC |