3. without inside operator generate random values for the range 34-43 class packet; rand logic [7:0] a; constraint range { (a > 34) && (a < 43); } endclass module tb; packet p;
initial begin p = new(); $display("value of a (>34 and
2. constraint to generate unique numbers between 99 to 100 module tb(); class packet; rand int a; real y; constraint c1{a inside {[990:1000]};} function void post_randomize(); y=a/10.0; $display("\t\t\t uniquw valus is %2f", y); endfunction endclass initial begin packet p1=new(); repeat(20) begin p1.randomize(); end end endmodule
class NumberGenerator; rand bit [19:0] num; constraint sum_first_last { num inside {[100000:999999]}; (num / 100000) + (num % 10) == 8; } function void display(); $display("Generated number: %d", num); endfunction endclass module test; initial begin NumberGenerator gen = new(); if (gen.randomize()) begin gen.display(); end else begin $display("Randomization failed."); end end endmodule
beautifully explained
Thank you:)
best explained
@@Muskaanhayat Thank you 🎉💜
Excellent
Thank you:)
3. without inside operator generate random values for the range 34-43
class packet;
rand logic [7:0] a;
constraint range { (a > 34) && (a < 43); }
endclass
module tb;
packet p;
initial begin
p = new();
$display("value of a (>34 and
constraint range { (a >= 34) && (a
@@susheelapatagar thanks for correction
mam provide some more practice questions
@@shivaibara4733 checkout my 'community' section in Home page for quiz and constraint questions.
2. constraint to generate unique numbers between 99 to 100
module tb();
class packet;
rand int a;
real y;
constraint c1{a inside {[990:1000]};}
function void post_randomize();
y=a/10.0;
$display("\t\t\t uniquw valus is %2f", y);
endfunction
endclass
initial begin
packet p1=new();
repeat(20) begin
p1.randomize();
end
end
endmodule
Correct✌
Could u share u first question in the comments......
class NumberGenerator;
rand bit [19:0] num;
constraint sum_first_last {
num inside {[100000:999999]};
(num / 100000) + (num % 10) == 8;
}
function void display();
$display("Generated number: %d", num);
endfunction
endclass
module test;
initial begin
NumberGenerator gen = new();
if (gen.randomize()) begin
gen.display();
end else begin
$display("Randomization failed.");
end
end
endmodule
Can we also use int instead of bit data types
Yes we can.
mam explain how to generate two conscutive ones for 16 bit variable
Ok. I will upload one short video for this question.