• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Constraints, randomize bits in a vector

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 64
  • Views 16389
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Constraints, randomize bits in a vector

archive
archive over 19 years ago

I want to randomly set a weighted random number of bits in a vector.

The code below randomizes the number of bits that are set based on the weights provided, but I haven't figured out how to insert the weighted random number of bits randomly in a vector.

I have some code commented out that was an idea I had, which may be wrong, but functions in constraints doesn't seem to be supported.

I'm using IUS5.6-s2. Thanks.

To run: ncverilog sv_test.v +sv

module sv_test();
class constraints;
bit [31:0] bit_vector;
rand bit [31:0] bit_vector_rand;
rand bit [5:0] count;

constraint c0 {
count dist { [1:5]:/40,[6:25]:/20,[26:31]:/40 };
}

function int count_ones ( input bit [5:0] w );
for( count_ones = 0; w != 0; w = w >> 1 )
count_ones += w & 1'b1;
endfunction

// constraint c1 {
// count==count_ones(bit_vector_rand);
// }

function void post_randomize();
bit_vector = {{32{1'b1}},{32{1'b0}}} >> (32-count);
$display("%d",count);
$display("x%h",bit_vector);
// $display("x%h",bit_vector_rand);
endfunction

endclass

constraints a = new;

integer num_iterations;

integer seed;
initial begin
num_iterations = 10;
if ($value$plusargs("SEED=%d",seed)) begin
$display("Using SEED=%d", seed);
end else begin
$display("Using default seed");
end
process::self.srandom(seed);
for (int i = 0; i
if ( a.randomize() == 0 ) begin
$display("%d error!",i);
end
end
end
endmodule


Originally posted in cdnusers.org by ross.weber@unisys.com
  • Cancel
Parents
  • archive
    archive over 19 years ago

    test posting
    www.xtreme-eda.com


    Originally posted in cdnusers.org by coreygoss
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 19 years ago

    test posting
    www.xtreme-eda.com


    Originally posted in cdnusers.org by coreygoss
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information