quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

In this section we will covering randomization feature of Vera language.

   

space.gif

  • Random Variables
  • Constraint block
  • Dynamic constraint modification
  • Out of body constraints
   

space.gif

In earlier chapter we had used method random() for generating random integer values, this is vera build in method which returns 32 bit random value. This is no good for object randomization (here object mean class based). To help with class based object's to be randomized, vera supports rand variables and randomize() method, we will be looking this in detail below.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Random Variables

Class properties can be declared random using the rand and randc modifiers.

   

space.gif

  • Vera can randomize scalar variables of type integer, reg, and enumerated type. Bit variables can be any size supported by Vera.
  • Arrays can be declared rand or randc, in which case all of their member elements are treated as rand or randc.
  • Associative arrays, dynamic arrays and SmartQs can be declared rand or randc.
  • Associative arrays can be declared rand or randc, however, only the elements in the numeric key range of 0 to n-1 will be randomized, where n is declared using the optional assoc_size keyword.
   

space.gif

As seen above variables can be declared as

   

space.gif

  • rand
  • randc
   

space.gif

rand

Variables declared with the rand keyword are standard random variables. Their values are uniformly distributed over their range.

   

space.gif

   

space.gif

randc

Variables declared with the randc keyword are random-cyclic variables that cycle through all the values in a random permutation of their declared range. Random-cyclic variables can only be reg or enumerated types, and are limited to a maximum size of 16 bits, so the maximum range for any randc variable is 0 to 65535.

   

space.gif

The basic idea is that randc randomly iterates over all the values in the range and that no value is repeated within an iteration. When the iteration is finished, a new iteration is automatically started.

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Random Variables
   

space.gif


  1 enum pkt_type {UNICAST=11,MULTICAST,BROADCAST};
  2 
  3 class frame_t {
  4   rand pkt_type type;
  5   rand integer len;
  6   randc reg [1:0] no_repeat;
  7   rand reg  [7:0] payload [];
  8   // Constraint the members
  9   constraint legal {
 10     len >= 2;
 11     len <= 5;
 12     payload.size() == len;
 13   }
 14   // Print the members of the class
 15   task print() {
 16     integer i =0;
 17     printf("Packet type %s\n",type);
 18     printf("Size of frame is %0d\n",len);
 19     printf("Payload is ");
 20     for (i=0; i < len; i++) {
 21       printf(" %2x",payload[i]);
 22     }
 23     printf("\n");
 24     printf("no_repeat is %d\n",no_repeat);
 25   }  
 26 }
 27 
 28 program rand_ex {
 29    frame_t frame = new();
 30    integer j = 0;
 31    // Print frame before randomize
 32    printf("-------------------------------\n");
 33    frame.print(); 
 34    printf("-------------------------------\n");
 35    for (j = 0 ; j < 10;j++) {
 36      if (frame.randomize() == OK) {
 37        // Print frame after randomize
 38        frame.print(); 
 39      } else {
 40        printf("Failed to randomize frame\n");
 41      }
 42      printf("-------------------------------\n");
 43    }
 44 }
You could download file rand_ex.vr here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Random Variables
   

space.gif

 -------------------------------
 Packet type 
 Size of frame is x
 Payload is 
 no_repeat is x
 -------------------------------
 Packet type MULTICAST
 Size of frame is 3
 Payload is  0b df 40
 no_repeat is 0
 -------------------------------
 Packet type BROADCAST
 Size of frame is 3
 Payload is  fa 4e 15
 no_repeat is 1
 -------------------------------
 Packet type BROADCAST
 Size of frame is 5
 Payload is  c4 aa c4 cf 4f
 no_repeat is 2
 -------------------------------
 Packet type UNICAST
 Size of frame is 3
 Payload is  2c ce 05
 no_repeat is 3
 -------------------------------
 Packet type UNICAST
 Size of frame is 4
 Payload is  7a a2 f0 c9
 no_repeat is 0
 -------------------------------
 Packet type MULTICAST
 Size of frame is 4
 Payload is  df c5 d7 94
 no_repeat is 3
 -------------------------------
 Packet type BROADCAST
 Size of frame is 4
 Payload is  f4 d9 4f 00
 no_repeat is 1
 -------------------------------
 Packet type UNICAST
 Size of frame is 5
 Payload is  45 f2 a2 a1 fd
 no_repeat is 2
 -------------------------------
 Packet type UNICAST
 Size of frame is 4
 Payload is  20 e1 97 c6
 no_repeat is 3
 -------------------------------
 Packet type UNICAST
 Size of frame is 2
 Payload is  b8 1c
 no_repeat is 0
 -------------------------------
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com