#! perl -slw use strict; use List::Util qw[ sum ]; use Data::Dump qw[ pp ]; our $X //= 10; our $Y //= 10; my @xs = map -3+rand 6, 1 .. $X; my @ys = map -3+rand 6, 1 .. $Y; my %bins; for my $x ( @xs ) { my $xc = ( int( $x * 10 ) + 0.5 ) / 10; for my $y ( @ys ) { my $yc = ( int( $y * 10 ) + 0.5 ) / 10; ++$bins{ "$xc:$yc" }; } } pp \%bins; printf "Buckets used: %d, total values %d \n", scalar keys %bins, sum values %bins; #### c:\test>824030 -X=10 -Y=10 { "-0.15:-0.55" => 2, "-0.15:-1.25" => 1, "-0.15:-2.15" => 1, "-0.15:-2.25" => 1, "-0.15:-2.35" => 1, "-0.15:-2.45" => 1, "-0.15:-2.55" => 1, "-0.15:0.05" => 1, "-0.15:2.05" => 1, "-1.15:-0.55" => 2, "-1.15:-1.25" => 1, "-1.15:-2.15" => 1, "-1.15:-2.25" => 1, "-1.15:-2.35" => 1, "-1.15:-2.45" => 1, "-1.15:-2.55" => 1, "-1.15:0.05" => 1, "-1.15:2.05" => 1, "-1.65:-0.55" => 2, "-1.65:-1.25" => 1, "-1.65:-2.15" => 1, "-1.65:-2.25" => 1, "-1.65:-2.35" => 1, "-1.65:-2.45" => 1, "-1.65:-2.55" => 1, "-1.65:0.05" => 1, "-1.65:2.05" => 1, "-1.75:-0.55" => 4, "-1.75:-1.25" => 2, "-1.75:-2.15" => 2, "-1.75:-2.25" => 2, "-1.75:-2.35" => 2, "-1.75:-2.45" => 2, "-1.75:-2.55" => 2, "-1.75:0.05" => 2, "-1.75:2.05" => 2, "-2.55:-0.55" => 2, "-2.55:-1.25" => 1, "-2.55:-2.15" => 1, "-2.55:-2.25" => 1, "-2.55:-2.35" => 1, "-2.55:-2.45" => 1, "-2.55:-2.55" => 1, "-2.55:0.05" => 1, "-2.55:2.05" => 1, "-2.65:-0.55" => 2, "-2.65:-1.25" => 1, "-2.65:-2.15" => 1, "-2.65:-2.25" => 1, "-2.65:-2.35" => 1, "-2.65:-2.45" => 1, "-2.65:-2.55" => 1, "-2.65:0.05" => 1, "-2.65:2.05" => 1, "0.05:-0.55" => 2, "0.05:-1.25" => 1, "0.05:-2.15" => 1, "0.05:-2.25" => 1, "0.05:-2.35" => 1, "0.05:-2.45" => 1, "0.05:-2.55" => 1, "0.05:0.05" => 1, "0.05:2.05" => 1, "0.25:-0.55" => 2, "0.25:-1.25" => 1, "0.25:-2.15" => 1, "0.25:-2.25" => 1, "0.25:-2.35" => 1, "0.25:-2.45" => 1, "0.25:-2.55" => 1, "0.25:0.05" => 1, "0.25:2.05" => 1, "2.95:-0.55" => 2, "2.95:-1.25" => 1, "2.95:-2.15" => 1, "2.95:-2.25" => 1, "2.95:-2.35" => 1, "2.95:-2.45" => 1, "2.95:-2.55" => 1, "2.95:0.05" => 1, "2.95:2.05" => 1, } Buckets used: 81, total values 100