STACK: Paired Random Variables

STACK: Paired Random Variables

by David Hilsen -
Number of replies: 2

In our use of STACK we often use multiple random variables within the question. Is there a way to generate paired random variables in which only predetermined paired values are displayed?

For example, one might have the following random variables:

x : rand([ 1,3,5 ]);

y : rand([ 2,4,6 ]);

However, only particular pairings of x and y are acceptable for the problem, say:

x : 1 , y : 2

x : 3 , y : 4

x : 5 , y : 6 

Is there a function that can be used to accomplish this?

(In this example there is a single mathematical function that relates the two variables that could be used to generate the second variable. However, my question is for the more general case in which no single mathematical function relates the two variables requiring specific numerical pairs be determined in advance.)


Average of ratings: -
In reply to David Hilsen

Re: STACK: Paired Random Variables

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers

David,

What about

p:rand([ [1,2], [3,4], [5,6] ])

x:first(p)

y:second(p)

?

If the function "rand" receives a list as its argument it makes a random selection from the list.  It is easy to have lists of "things" such as other lists or structured expressions.  

Chris


In reply to Christopher Sangwin

Re: STACK: Paired Random Variables

by David Hilsen -

Thank you Chris. You provided an excellent solution!