amar712 Posted July 13, 2016 Report Share Posted July 13, 2016 I have a variable logic [31:0] id which is not declared as rand or randc. I need different id's each time into an array logic [31:0] id_array [16]. logic [31:0] id;logic [31:0] id_array [16];foreach(id_array) beginstd::randomize(id);id_array = id;end In the above code, there is a possibility of getting duplicate ids in the array. How do I change the code to get unique ids in the array ? Quote Link to comment Share on other sites More sharing options...
imajeeth Posted July 13, 2016 Report Share Posted July 13, 2016 Write a constraint for that. The idea is, for each element in the array, you iterate through all the elements of the array. If the index don't match, the make sure the values are not equal. This is O(n^2) complexity, there could be a better way of accomplishing the same as well. constraint c_unique_array_value { foreach(id_array) { foreach(id_array[j]) { if(i != j) id_array != id_array[j]; } } } Quote Link to comment Share on other sites More sharing options...
apfitch Posted July 13, 2016 Report Share Posted July 13, 2016 You should be able to use std::randomize(id_array) with { unique {id_array}; }; Untested though, regards Alan amar712 1 Quote Link to comment Share on other sites More sharing options...
karandeep963 Posted August 10, 2016 Report Share Posted August 10, 2016 I think UNIQUE KEYWORD does well , I have used it with Synopsys VCS, a quick example ::-> http://www.edaplayground.com/x/6AHE Not sure about cadence incisive, sometime back raised CCR for enhancement for this feature , not sure whether it is available. But yes, this unique keyword does much beautification to my code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.