If we start from your SQL query:
clearly this will return a set of unique values (presumably all positive integers). Now the next step you want is... (I'm guessing) to generate a bunch of randomly selected subsets from this list of values? Something else? Let's suppose the list returned by that query is:SELECT DISTINCT Number_count FROM Region_lookup_for_eligible_regions
That's a list of 10 elements. (If your actual list is bigger or smaller, what sort of size should we expect?) Let's suppose further that these query results are stored in "@array", and you want to select 4 groups of randomly selected members from this list, such that each group contains 5 distinct elements. (I don't know if that's really what you want to do, because you have not yet provided, in either this thread or the other one on this topic, any clear example of what your desired output is.) Maybe something like this:2 4 5 8 9 12 15 17 21 22
You can run that and see what the output is. You can also play with the input values and the parameters for controlling the number and size of subsets. If there is actually something different that you want, you will need to provide a coherent example of what you really want.#!/usr/bin/perl use strict; use List::Util qw/shuffle/; sub get_random_subsets { my ( $n_sets, $set_size, @superset ) = @_; my @sets; for my $set ( 1 .. $n_sets ) { push @sets, [ (shuffle( @superset ))[1..$set_size] ]; } return \@sets; } my @query_data = qw/2 4 5 8 9 12 15 17 21 22/; my $rand_sets = get_random_subsets( 4, 5, @query_data ); print "input superset: @query_data\n random subsets:\n"; for my $set ( @$rand_sets ) { print " @$set\n"; }
In reply to Re: Updating sub for random number generation
by graff
in thread Updating sub for random number generation
by Win
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |