# $urandom\_unsigned\_value

**URL:** <https://verificationacademy.com/forums/t/urandom-unsigned-value/35035>\
**Category:** SystemVerilog\
**Tags:** signed, urandom, SystemVerilog, randomization\
**Created:** [September 14, 2018, 3:57pm UTC](https://verificationacademy.com/forums/t/urandom-unsigned-value/35035 "2018-09-14T15:57:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh\_6](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@Mahesh\_6](https://verificationacademy.com/forums/u/Mahesh_6)\
**Post date:** [September 14, 2018, 3:57pm UTC](https://verificationacademy.com/forums/t/urandom-unsigned-value/35035/1 "2018-09-14T15:57:51Z")

</div>

$urandom generates unsigned values. Consider the following;

1. int a1;  
a1 = $urandom;  
//generates both positive and negative numbers.

2. int unsigned a2;  
a2 = $urandom;  
//generates only positive numbers.

3. int unsigned a3;  
a3 = $random;  
//generates only positive numbers with ‘$random’ keyword and not ‘$urandom’.

So, in order to generate positive numbers, explicit keyword ‘unsigned’ is required. This shows that there is no much difference between $random and $urandom.

In a simpler manner, without declaring the explicit keyword, we can still generate positive numbers;

1. int a4;  
a4 = $urandom\_range(200,0);  
//only positive numbers.

Can we make best practice of method 4) for simiplicity ?

---

<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:** [September 14, 2018, 4:17pm UTC](https://verificationacademy.com/forums/t/urandom-unsigned-value/35035/2 "2018-09-14T16:17:14Z")

</div>

_In reply to [Mahesh K](https://verificationacademy.com/forums/t/urandom-unsigned-value/35035):_

1. is incorrect. Both $random and $urandom generate 32-bit numbers. As with any assignment, the _signed-ness_ of a value only affects sign-extension when going from a narrow signed value to a wider signed value.

If you only want to deal with positive numbers, then only use unsigned data types.

Also, do not use $random as it provides no stability or global seed control.
