Range in Global Variables using Random Variables

Range in Global Variables using Random Variables

by Ajay Deo -
Number of replies: 4

Hello,

I have to define following variables in a "Formula" based question.

a = {10:20:1}

The second variable depends on "a" and has range from

b = a/2 to 2

while the third variable "d" depends on "a" and "b", with range from:

d = b to a-b

Can you please help me to setup this question?

Any help is highly appreciated.

With best regards,

Ajay

Average of ratings: -
In reply to Ajay Deo

Re: Range in Global Variables using Random Variables

by Dipo Adeniyi -
Hello Ajay,

For a, use a = {10:20:2} as this will ensure that all your a's are even numbers.

For b, since you have already defined b as b = a/2, the lowest value of a from the above is 10, so smallest value of b = 5. (Not sure if you want all b's to be an number, so define b1 = {1:4}), so that b = a/2 - b1

For d: Let say a = 10, then b = 5, a - b = 5. If a = 16, b = 8, a - b = 8, again if a = 20, b = 10 and a - b = 10. This means d will be equal to b = a-b always. If this is what you need then you can as well define d = b.

I hope this help.
In reply to Dipo Adeniyi

Re: Range in Global Variables using Random Variables

by Ajay Deo -

Thank you Dipo for the quick response.

But, that is not really what I am looking for.

Let's assume "a" = 10, then "b" should be {2:5:1}. Now, if "b" = 5 then "d" = 5 (only); on the other hand, if "b" = 2 then "d" can be anything between 2 (i.e. "b") and 8 (i.e. "a-b")

So, basically, for random value of "a" from: a = {10:20:2}

b = {2:0.5*a:1}

d = {b:a-b:1}


I know that above doesn't work!

The question is: How to setup this? The figure in the original post may help to clarify the situation.
In reply to Ajay Deo

Re: Range in Global Variables using Random Variables

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Ajay,

One way to do this is as follows:

Random variables
a={10:21:2};
r1={0:1.1:0.1};
r2={0:1.1:0.1};

Global variables
brange = a/2 - 2;
b = floor(2 + r1*brange);
drange= (a-b) - b;
d = floor(b + r2*drange);
Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Range in Global Variables using Random Variables

by Ajay Deo -

Dear Dominique,

Thank you very much for your reply.

It worked exactly as I was expecting.

Regards,

Ajay