Randomization

66 views
Skip to first unread message

lakshmi priya

unread,
Oct 10, 2021, 3:43:25 AM10/10/21
to eda-pla...@googlegroups.com
Hi All,

If I give randomization of a variables with inline constraint  say sq.randomize with {a>20;} 

Im getting output as square of a= 722902799
square of a=-1016618271
Please find the link for reference 

If I give sq.randomize with {a==20;}; I'm getting the expected output as 400


Why I it so , if I give  a>20 it's giving value as  some random numbers 

Please helpe through this.

EDA Playground

unread,
Oct 12, 2021, 4:56:49 AM10/12/21
to EDA Playground
You are getting overflow. An int is 32 bits. The random value picked for a is greater than 16 bits, so its square is greater than 32 bits. An int is also signed, so if you overflow a positive number, the left hand bit might be set and if it is, the number will be negative. That's what is happening here.

You need to constrain a to be less than 65536, ie 2^16.

lakshmi priya

unread,
Oct 12, 2021, 8:12:12 AM10/12/21
to EDA Playground
no , even if it did    sq1.randomize with {a<15;}; Im getting the same overflow.

square of a=-1424580858
square of a=-1143966684.
 here the random value picked will be within 15 (binary eqivalent is1111) . so square of this is  (15*15)=225 which will take(1111 1111)
8 bits  

please correct me if im wrong!

Gene Sullivan

unread,
Oct 17, 2021, 11:22:50 AM10/17/21
to EDA Playground
You should explicitly specify the upper and lower bounds in the constraint using inside, for example.

sq1.randomize with {a inside {[0:200]};};

lakshmi priya

unread,
Oct 25, 2021, 1:39:15 AM10/25/21
to EDA Playground

thank you so much!!
Reply all
Reply to author
Forward
0 new messages