#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub generate_clumpy_rand { my $num = shift // int(10*rand()+3); my @clumps; print "Generator has $num clumps\n"; for my $i (1 .. $num) { my @center_size = (rand, rand, rand, rand); print "clump 1 centered at ($center_size[0],$center_size[1]) " . "size is $center_size[2]x$center_size[3]\n"; push @clumps, \@center_size; } return sub { my @coord = (rand, rand); # Ensure we have a background of random dots over entire region return @coord if (.1 > rand); # Choose a clump, and map the coordinate into that clump my @clump = @{$clumps[rand @clumps]}; return ( ($coord[0]*$clump[2])+$clump[0], ($coord[1]*$clump[3])+$clump[1] ); } } my $clump_rand = generate_clumpy_rand(1); my @coord = $clumpy_rand->(); print Dumper(\@coord);