# Randomization only for part of data

**URL:** <https://verificationacademy.com/forums/t/randomization-only-for-part-of-data/32932>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, constraints-systemverilog\
**Created:** [March 3, 2017, 8:15pm UTC](https://verificationacademy.com/forums/t/randomization-only-for-part-of-data/32932 "2017-03-03T20:15:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sekharece413](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sekharece413](https://verificationacademy.com/forums/u/sekharece413)\
**Post date:** [March 3, 2017, 8:15pm UTC](https://verificationacademy.com/forums/t/randomization-only-for-part-of-data/32932/1 "2017-03-03T20:15:41Z")

</div>

hi ,

i am new to system verilog randomization , can i know how to randomize the part of the data only , for example i have 8 bit data , in that 3bit is crc , which i do not want to randomize, like to calculate and replace that bit with it return value .

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [March 3, 2017, 8:47pm UTC](https://verificationacademy.com/forums/t/randomization-only-for-part-of-data/32932/2 "2017-03-03T20:47:57Z")

</div>

_In reply to [sekharece413](https://verificationacademy.com/forums/t/randomization-only-for-part-of-data/32932):_  
There are a few different things you can do:

1. You can constrain the crc bit with the function

```verilog
constraint c_crc {data[7:5] == crc_func(data[4:0]); }

```

1. After randomization, you can just replace the crc bits with the return value of the function. It will not matter if they were random before.
2. You can add a constraint that leaves the 3 bits in their current state.

```verilog
constraint c_crc {data[7:5] == const'(data[7:5]); }

```

I think 1) is your best option.
