Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Đăng ký
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
semicon_lab.jpg

HOW TO GENERATE AN ARRAY OF UNIQUE RANDOM VALUES

Email In PDF.

Now a days in many verification scenarios it require to create a set of random instructions or addresses with each unique values or we can say that no repeating values, usually represented as elements in a dynamic array. 

Earlier versions of SystemVerilog required you to use either nested foreach loops to constraint all combinations of array elements so that they would not be equal to each other. Or else repeatedly randomize one element at a time, and then constraining the next element to not be in the list of already generated values.

The new unique constraint (new feature of 1800-2012) lets you use one statement to constraint a set of variables or array elements to have unique values. 

In the following example when randomized, this class generates a set of ten unique values from 0 to 15.

 class set_unique_val;

rand bit [3:0] data[10];

constraint uniq { unique {data};

}

endclass : set_unique_val

You can also add other non-random variables to the set of unique values which has the effect of excluding the values of those variables from the set of unique values. 

In the following example when randomized, this class generates a set of ten unique values excluding the values 0, 5 and 15.

 class set_unique_val;

 rand bit [3:0] data[10];

const bit [3:0] excludes[] = {0, 15};

 constraint uniq {

unique {data, excludes, 5};

}

endclass : set_unique_val

endclass : set_unique_val 

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Lần cập nhật cuối ( Thứ ba, 14 Tháng 9 2021 18:52 )  

Related Articles

Chat Zalo