Exclude data from $urandom_range

Hi,

I would like to exclude some value from a $urandom_range.
I have inherited this randomisation code in inside a task.

So basically I would like to exclude: 0x2a, 0x2b and 0x2c from

$urandom_range(8'hff, 8'h0)

Is there a solution without doing it with constraint and class?

Rgds

In reply to Ep1c F4iL:
Hi, You can try something like this

while(1) begin
val = $urandom_range(8'hFF, 8'h00);
if(!val inside {0x2a,  0x2b, 0x2c})
break;
end 

In reply to Mukesh Saha:

You do not need s class to randomize a variable. You can do this outsize of a class.

randomize(val) with {!(val inside {8'h2a, 8'h2b, 8'h2c}); };

Hi,

I have used the following:


      do 
        idx = $urandom_range(8'hFF,0);
      while (idx != (8'h2A || 8'h2B || 8'h2C));

Regards

Dave,
Finally I switched to your solution … stylish and one-liner
Thank you

In reply to dave_59:

Hello,

How to randomize the value from an array excluded the one already randomized before.

for example, the content in the array is from 1 to 100.
and first time we randomize from 1 to 100 and get 53.
and second time we still randomize from 1 to 100 but we don’t want 53 anymore. it likes that we randomize from 1 to 52 and 54 to 100. (let it say we get 23)
and third time we don’t want 23 or 53 anymore…

May I know what’s the easiest way to implement it ?

Thank you

In reply to zz8318:

It would help to ask this as a new question. I’m not sure if your question had any relation to the question above.

You build a list of previously used values in a queue

rand bit [7:0] val;
bit [7:0] list[$];
function void post_randomize;
   list.push_back(val); // if not in a class, just add this line after calling randomize. 
endfunction

Then you can put that list in the constraint

randomize(val) with {!(val inside {8'h2a, 8'h2b, 8'h2c, list}); };

Or you can use a separate constraint

constraint val_not_in_list{ unique {val, list};}

In reply to dave_59:

Thanks Dave

In reply to dave_59:

Hi Dave,

Is there a way, i can apply distribution in above randomization condition ?

Thanks,
Nainesh

In reply to nainesh:

Please ask as a new question with the constraint you want add a distribution to.