# Basic Randomization in OSVVM

## 1. Randomizing Integers

The basic randomization generates an integer value that is either within some range or within a set of values. The set of values and exclude values are all of type integer_vector (defined in VHDL-2008). The examples below show the basic randomization overloading. When a value of integer_vector is specifed, the extra set of parentheses denote that it is an aggregate value.

```RandomGenProc : process
variable RV      : RandomPType ;         -- protected type from RandomPkg
variable DataInt : integer ;
begin
RV.InitSeed (RV'instance_name)  ;         -- Generate initial seeds

-- Generate a value in range 0 to 255
DataInt := RV.RandInt(0, 255) ;
. . .
-- Generate a value in range 1 to 9 except exclude values 2,4,6,8
DataInt := RV.RandInt(1, 9, (2,4,6,8)) ;
. . .
-- Generate a value in set 1,3,5,7,9
DataInt := RV.RandInt( (1,3,7,9) ) ;  -- note two sets of parens required
. . .
-- Generate a value in set 1,3,5,7,9 except exclude values 3,7
DataInt := RV.RandInt((1,3,7,9), (3,7) ) ; ```

```impure function RandInt (Min, Max : integer) return integer ;
impure function RandInt (Min, Max: integer; Exclude: integer_vector)
return integer ;
impure function RandInt ( A : integer_vector ) return integer ;
impure function RandInt ( A : integer_vector; Exclude: integer_vector)
return integer ;```

## 2. Randomizing std_logic_vector, unsigned and signed

These same functions are available for types std_logic_vector(RandSlv), unsigned (RandUnsigned) and signed (RandSigned). Note that parameter values are still specified as integers and there is an additional value used to specify the size of the value to generate. For example, the following call to RandSlv defines the array size to be 8 bits.

```process
variable DataSlv : std_logic_vector(7 downto 0) ;
begin
. . .
-- Generate a value in range 0 to 255
DataSlv := RV.RandSlv(0, 255, 8) ;
. . .
-- Generate a value in range 1 to 9 except exclude values 2,4,6,8
DataSlv := RV.RandSlv(1, 9, (2,4,6,8), 8) ;
-- Generate a value in set 1,3,5,7,9
DataSlv := RV.RandSlv( (1,3,7,9), 8 ) ;  -- note two sets of parens required
. . .
-- Generate a value in set 1,3,5,7,9 except exclude values 3,7
DataSlv := RV.RandSlv((1,3,7,9), (3,7), 8 ) ; ```

```impure function RandSlv (Min, Max, Size : natural) return std_logic_vector ;
impure function RandSlv (Min, Max : natural ; Exclude: integer_vector ; Size : natural)  return std_logic_vector ;
impure function RandSlv
(A: integer_vector ; size : natural ) return std_logic_vector ;
impure function RandSlv (A: integer_vector ; Exclude: integer_vector ; Size : natural)  return std_logic_vector ;```

## 3. Randomizing Real

The function, RandReal supports randomization for type real. The function with a range, like the procedure Uniform, never generates its end values. RandReal has the following overloading:

```impure function RandReal ( Min, Max : real ) return real ;
impure function RandReal ( A : real_vector ) return real ;
impure function RandReal ( A, Exclude : real_vector ) return real ;```

## 4. Randomizing Time

The function, RandTime supports randomization for type time. RandTime supports the same overloading as RandInt. These are shown below:

```impure function RandTime (Min, Max : time ; Unit : time := ns) return time ;
impure function RandTime
(Min, Max : time ; Exclude : time_vector ; Unit : time := ns) return time ;
impure function RandTime (A : time_vector) return time ;
impure function RandTime (A, Exclude : time_vector) return time ;```