Forum archive 2000-2006

Arnold K. Pizer - non random values

Arnold K. Pizer - non random values

by Arnold Pizer -
Number of replies: 0
inactiveTopicnon random values topic started 3/2/2001; 11:32:15 AM
last post 3/2/2001; 11:44:38 AM
userArnold K. Pizer - non random values  blueArrow
3/2/2001; 11:32:15 AM (reads: 856, responses: 1)
Here is a question we received via private email. The answer is in the response.

I would like to write a question where the input values are not random but rather are drawn from a table. I want the numbers to come out nice in the end, and to do that they have to be carefully arranged so that the correct things are perfect squares, divisible by certain things, etc etc. There are two values to be specified, a and b, and I have about a dozen pairs that will work. Can any of you advise me as to how this is done, and/or point me to an example that does this? Thanks

<| Post or View Comments |>


userArnold K. Pizer - Re: non random vaules  blueArrow
3/2/2001; 11:44:38 AM (reads: 1065, responses: 0)
This is easy to do. For an example look at e.g. setAlgebra2Powers/srw1_2_26.pg

Suppose you want to work with the pairs (a,b) = (7,15), (11,2), (2,1), and (-3,3). Set up the two arrays

@a_val = (7,11,2,-3);
@b_val = (15,2,1,3);

Since arrays in Perl are indexed starting with zero (so we have indices 0,1,2,3 in the above example), we pick an index tag by

$tag = random(0,3,1);

Then $a_val[$tag] and $b_val[$tag] will be one of the random pairs above.

Tom Shemanske's WeBWorK Newbie Guide (under write/modify problems) describes the syntax for arrays in Perl.

<| Post or View Comments |>