how to randomize and array of elements, so that the elements are multiples of 3 or 4.
I want more multiples of 3, dist is not working if used in this context.
class packet;
rand int unsigned q[10];
constraint dumb_way
{
foreach(q[i])
{
q[i] inside {[1:50]};
//(q[i] %3 ==0 ) || (q[i] %4==0);
q[i] dist {(q[i] %3 ==0 ):=2 , (q[i] %4==0):=1}; --> syntax error
}
}
function void post_randomize();
endfunction
endclass: packet
In reply to CRVAddict:
You do not get a syntax error, you get an unsolvable constraint error. There is no way q[i] can equal (q[i]%3 ==0) or (q[I]%4 ==0).
What you want is
constraint right_way {
foreach(q[i]) {
q[i] inside {[1:50]};
q[i] % 3 ==0 || q[i] % 4 ==0;
(q[i] % 3 ==0) dist {0:=1, 1:=2};
(q[i] % 4 ==0) dist {0:=2, 1:=1};
}
}
You could also do
rand bit m[10];
constraint another_way
{
foreach(q[i]) {
q[i] inside {[1:50]};
m[i] dist {0:=1, 1:=2};
m[i] -> q[i] % 3 ==0;
!m[i] -> q[i] % 4 ==0;
}
}
In reply to dave_59:
Thanks Dave!!
I wanted more 3’s so i am assuming you meant this
constraint right_way {
foreach(q[i]) {
q[i] inside {[1:50]};
q[i] % 3 ==0 || q[i] % 4 ==0;
(q[i] % 3 ==0) dist {0:=2, 1:=1};
(q[i] % 4 ==0) dist {0:=1, 1:=2};
}
}
In reply to CRVAddict:
I don’t think so. Did you try it?
Hi Dave,
(q[i] % 4 ==0) dist {0:=2, 1:=1}; can be skipped in below constraint.
When (q[i]%3==0) is False, the left over choice is (q[i]%4==0). Am I missing something?
constraint right_way {
foreach(q[i]) {
q[i] inside {[1:50]};
q[i] % 3 ==0 || q[i] % 4 ==0;
(q[i] % 3 ==0) dist {0:=1, 1:=2};
(q[i] % 4 ==0) dist {0:=2, 1:=1};
}
}
Same as
constraint right_way {
foreach(q[i]) {
q[i] inside {[1:50]};
q[i] % 3 ==0 || q[i] % 4 ==0;
(q[i] % 3 ==0) dist {0:=1, 1:=2};
}
}
Hi Dave,
How does the dist work in this case:
(q[i] % 3 ==0) dist {0:=1, 1:=2}; -> line 3
(q[i] % 4 ==0) dist {0:=2, 1:=1}; -> line 4
In line 3, if we use 0:=2 and 1:=1 will it not produce more divisible by 3?
In reply to j_w:
No, then you are asking q[i] % 3 ==0 to be false twice as many times as it is true.