Constraint for error injection

In reply to syed taahir ahmed:

OK, now you are a little bit clearer, but still a lot of missing information. Let’s create an array of bits indicating which bits in your pattern should have an error

bit [0:999] pattern;
rand bit error_bits[1000]; // bit set if inject error

You never stated what an error looks like, but I will assume an error is an inverted bit. You can generate the errors with this in post_randomise();

foreach (error_bits[b]) pattern[b] ^=error_bits[b];

You want to inject N error bits into a pattern of 1000 bits. You never specified how many bits out of those 1000 could have an injected error, but let me assume a range from 1 to 100. You constraints would then look like

constraint c {
     error_bits.sum() with (int'(item)) inside {[1:100}; // number of bits that will have an error
     foreach (error_bits[b]) b>0 -> !error_bits[b] || !error_bits[b-1]; // no consecutive errors
      foreach (error_bits[b]) const'(error_bits[b]) -> !error_bits[b];  // no repeated errors
}

You need to repeatedly call randomize() 10 times to get 10 error scenarios.