Randc solve after

Hi,

i’m struggling with a tricky randomization issue.
With this example code


class rand_C
randc int rand_a;
rand int rand_b;

constraint a_c {rand_a inside {0,1,2,3,4,5,6,7,8,9,10};}
constraint b_c {rand_b inside {4, 8, 10};}

constraint a_b {rand_a < rand_b ; solve rand_b before rand_a]}
endclass : rand_C


This a wrong piece of code, I know, because randc variables are always solved before any other (LRM 18.5.10); but i was wondering if there’s a way to avoid this LRM limitation.

In reply to alexkidd84:

What are you trying to achieve with the solve before construct?

In reply to dave_59:

I just want to randomize rand_b to find the max value (1st step) for the rand_a randomization (2nd step).

In reply to alexkidd84:

You have conflicting requirements. You cannot cycle through all the values of rand_a if you choose rand_b first. In table below, after the 6th step, there is no number you can choose without repeating a value before exhausting other unused numbers.

Step rand_a rand_b
1 3 4
2 2 8
3 1 10
4 0 4
5 4 8
6 ??? 4

In reply to dave_59:

In reply to alexkidd84:
You have conflicting requirements. You cannot cycle through all the values of rand_a if you choose rand_b first. In table below, after the 6th step, there is no number you can choose without repeating a value before exhausting other unused numbers.

Step rand_a rand_b
1 3 4
2 2 8
3 1 10
4 0 4
5 4 8
6 ??? 4

Ok, I forgot another requirement. The randomization of rand_b should be done only at first time of class randomization. So the table should be:

Step rand_a rand_b
1 3 4
2 2 4
3 0 4
6 1 4

In reply to alexkidd84:

That’s a significant piece of missing information.

Remove the solve before construct from your example

You can explicitly call randomize(rand_b), the subsequently call randomize(rand_a)

Or you can add a post_randomize() function to turn off rand_b.rand_mode(0).

In reply to dave_59:
I made something similiar to what you wrote, but I can’t realize how it will be with post_randomize() function:


randC c1;

if( first iteration) begin
  c1.rand_b.rand_mode(1);
  c1.rand_a.constraint_mode(0);
  c1.randomize(rand_b)
end

c1.rand_b.rand_mode(0);
c1.rand_a.constraint_mode(1);
c1.randomize(rand_a);

Interesting prob, I want to give a try. Is this something you want?

Edit: just found this post, you two are having the same problem. Is it an interview question?
-An

In reply to AnPham:

Interesting prob, I want to give a try. Is this something you want?
Edit: just found this post, you two are having the same problem. Is it an interview question?
-An

Yes you’re right, we are working on the same issue