Randomization Questions

I have a few doubts related to randomization

(1) rand to randc Conversion using unique


        class rand_2_randc ;
          rand bit [2:0] b ;
               bit [2:0] b_q[$] ;

          constraint UNIQUE {  ! ( b inside { b_q } ) ; }

          function void post_randomize() ;
               b_q.push_back(b);

               if ( b_q.size() == 8 ) 
                   b_q.delete();
 
          endfunction

        endclass

      

LRM says ::
“To reduce memory requirements, implementations may impose a limit on the maximum size of a randc
variable, but it shall be no less than 8 bits”

So a simulator may not support 32-bit randc variable

If I were to declare the packed dimensions of both ‘b’ and ‘b_q’ as 32-bit I would see performance issues

So I decide to split the 32-bit variable into two 16-bit variables


class rand_2_randc_Part2 ;
          rand bit [15:0] b1 , b2;
               bit [15:0] b1_q[$] , b2_q[$] ;

          constraint UNIQUE {  ! ( b1 inside { b1_q } ) ;
                               ! ( b2 inside { b2_q } ) ; 
                             }

          function void post_randomize() ;
               b1_q.push_back(b1);
               b2_q.push_back(b2); 

               if ( b1_q.size() == 2**16 ) 
                   b1_q.delete();

               if ( b2_q.size() == 2**16 ) 
                   b2_q.delete();
 
          endfunction

        endclass


[QA] My confusion is how do I achieve all 232 unique values ?

The above class won’t necessarily give me all 232 unique combinations if I call randomize() , 232 times on object of class rand_2_randc_Part2**

My next 2 questions are related to LRM .

(2)

LRM says ::
"Randomization shall not modify the actual object handle. "

[Q]**I understand that via constraints I can’t create objects , is the above line trying to say the same .
Or are there additional things too ?

LRM says ::
[b]" Object handles shall not be declared randc. "**

[Q][C] Why the above limitation ?
The properties within a object would be randomized only if the properties are rand/randc and the class handle is declared random too
( in another class as its property )

   **Why does it make any difference if the class handle is declared rand OR randc . 
   Its how the properties are defined within the class that should decide the values**

In reply to MICRO_91:

You’re going to run into performance problems no matter how you try to generate 4 billion unique random values. You will also run out of memory trying to store that many values in a queue. If you split the cycle into 2 16-bit random variables, the first 216 values will be unique. The chance of getting a repeat with the second 216 values is very low.

The rule that says that randomize() cannot modify the contents of a class variable is broader than the rule that randomize will never call the constructor. The constraint solver can only create a solution sets using integral values.

The rule that randc cannot not be used with class variables is just to keep the implementation simple.