Randomization control

This is to know whether there is an easier method to do this.

There is a packet
class A
{
rand int a;
rand int b;
rand int c;
rand int d;
rand int e;
rand int f;

constraint a_c{b==0->a==0;}
.
.
.
.
.
}

I have a task which randomizes A and does some operation on its members
task operate_on_A();
A obj_a;
assert(obj_a.randomize() with a==10;b==3;c==9;} // few values would be fixed, few random
endtask

From a test, i would like to call this task
d,e and f get random values as of now.
i would like to control from the test whether d,e,f would get random values or fixed values passed from the test when calling the task. If am passing fixed values, it should get the fixed values, else it should be randomized.
How can this be done in a generic manner and what is the best possible way in uvm ?

This is what the UVM factory is used for. You simply extend class A with the constraints you want to add or override. The class can also turn off the rand_mode settings of the variables you want to stay fixed. This also a good reason not to use the randomize with {} clause unless you have constraints that no one is allowed to override.

class A_test1 extends A;
`uvm_object_utils(A_test1);
function new(string name);
  super.new(name);
  f.rand_mode(0);
  f = 10; // f is fixed at 10
end
constraint a_c {b==1 -> c==1 ;}
endclass

Then in your test, you set an override

factory.set_override_by_type (.orig_type(A::get_type), .override_type(A_test1::get_type));