Randomly selecting Variables

G

George

Hi,
I am sorry and not sure if this query is directly related to perl, but
since I want to do this trick in perl so

I have a 30 variables out of which I need to randomly select 15 and
then randomly equate them numbers between 01 and 90,
Thanks
 
A

Anno Siegel

George said:
Hi,
I am sorry and not sure if this query is directly related to perl, but
since I want to do this trick in perl so

I have a 30 variables out of which I need to randomly select 15 and

Read "perldoc -q shuffle" and adapt it to your situation.
then randomly equate them numbers between 01 and 90,

If "equate" means what I would call "assign" that should be easy.

Anno
 
S

Scott Bryce

George said:
Hi,
I am sorry and not sure if this query is directly related to perl, but
since I want to do this trick in perl so

I have a 30 variables out of which I need to randomly select 15 and
then randomly equate them numbers between 01 and 90,
Thanks

Your problem definition is confusing. What is the significance of having
exactly 30 variables in the pool, if you want to select 15 out of 90
values? Could you use a hash with 30 keys? (But why, if you only want to
use 15 of them?)

If you want to use 15 numbers randomly selected from a pool of 90
possible values, assign the values to 90 elements in an array, shuffle
the array, pull the first 15 values from the shuffled array.
 
A

Anno Siegel

[...]
If you want to use 15 numbers randomly selected from a pool of 90
possible values, assign the values to 90 elements in an array, shuffle
the array, pull the first 15 values from the shuffled array.

If it matters, modify the shuffling algorithm to return after 15 steps.
The "already shuffled" elements usually are a compact sub-array that
is easy to return. No need to shuffle the other 75 that aren't looked
at.

Anno
 
G

George

Scott said:
Your problem definition is confusing. What is the significance of
having exactly 30 variables in the pool, if you want to select 15 out
of 90 values? Could you use a hash with 30 keys? (But why, if you
only want to use 15 of them?)

If you want to use 15 numbers randomly selected from a pool of 90
possible values, assign the values to 90 elements in an array,
shuffle the array, pull the first 15 values from the shuffled array.

Those 30 vaiables are used in formating a tabular label defined in
format function , now out of 30 only 15 are assigned in one go , very
much like bingo tickets,
 
S

Scott Bryce

George said:
Those 30 vaiables are used in formating a tabular label defined in
format function , now out of 30 only 15 are assigned in one go , very
much like bingo tickets,

If you want to randomly assign 15 out of 30 scalars, things could get messy.

Can these 30 variables be stored as hash elements? Instead of $var_1,
$var_2, etc, use $hash{var_1}, $hash{var_2}, etc.

Load an array with the hash keys, shuffle them, then take the first 15
keys from the shuffled array. Assign the random numbers to those hash
elements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top