Constraint a parameter in a sequence item

Hi,

I have a sequence item eg: class abc #(int range=4) extends uvm_sequence_item

                          endclass

I want to add a constraint on range is make sure it’s less than a certain value say ‘10’. How to handle this case?

In reply to to_learn_uvm:

Hi,
I have a sequence item eg: class abc #(WIDTH) extends uvm_sequence_item.
I want to add a constraint on WIDTH is make sure it’s less than a certain value ‘x’. How to handle this case?

why do you want to constraint the class parameter?
what is use of the parameter in your class?

In reply to Rahulkumar Patel:

@rahulkumar,

I have updated the question. Why I want this constraint? - because I want to generate other data type value based on this int range. say if array index is less than 10,dont randomize the array, if its greater, rndomize it. But the user passes the range as class parameter.

In reply to to_learn_uvm:

In reply to Rahulkumar Patel:
@rahulkumar,
I have updated the question. Why I want this constraint? - because I want to generate other data type value based on this int range. say if array index is less than 10,dont randomize the array, if its greater, rndomize it. But the user passes the range as class parameter.

You cant randomize the parameter value of a class, it must be a constant.
Instead of creating class parameter, why don’t you create the rand variable in abc class?


class abc extends uvm_sequence_item;
  rand int range;
endclass

Then randomize the abc class object:


abcd item = new;
item.randomize() with {
  range == 4; // Or any value you want.
};

You can also add a constraint of range variable in abc class.

In reply to chris90:
Okay, Thanks Chris!.