USING std::randomize functio

i am trying to randomize a variable addr in the same class where it is defined , but it is not getting randomized. can anyone please let me know why its working ?

task main_phase(uvm_phase);
bit [63:0] addr1;
addr = std::randomize(addr1) with {addr1 <= end_addr ; addr1 >= start_addr;};


endtask

start_addr and end_addr are generated at run time.

In reply to samir singh:

I am able to randomize it in modelsim. Just see whether randomization succeeded or not by checking addr.
If not try printing start_addr,end_addr

The return value std::randomize() is 1’b1 for success, 0’b0 for failure. addr1 will be randomized if the constraint can be met.

In reply to dave_59:

hi dave,
i was trying to follow the example mentioned in sv lrm :

task stimulus( int length );
int a, b, c, success;
success = std::randomize( a, b, c ) with { a < b ; a + b < length };

success = std::randomize( a, b ) with { b - a > length };

endtask

based on the above example i was trying to randomize my addr1. start_addr and end_addr are generated before i am randomizing addr1 but its returing 0.
can you please let me know how can i randomize the same. suppose my start_addr is 5 and end_addr is 10 then addr1 can be anything between 5 and 10.

In reply to samir singh:

As i mentioned earlier print both the start_addr,end_addr values before calling randomize.

let say by mistake start_addr is 10 and end_addr is 5 in this case no value can be found by randomize function which satisfy the condition: addr1 <= end_addr ; addr1 >= start_addr;

In reply to Naven8:

Samir,

Show us a small complete testcase of what you want to do.

Dave

In reply to dave_59:

hi dave,
below is the part of code i am trying to use.
class xyz extends abc;
rand bit[63:0] addr;
task main_phase(uvm_phase phase);
rand bit [63:0] addr1 ;
phase.raise_objection(this,“starting sequence”);
if(!mss_env_obj.mss_mem_manager_obj.get_addr(start_addr,'hfffff,60,MSS_ECC_CORR))//this part is to get the address range,
`uvm_error(get_name(),$psprintf(“Could not allocate memory space”))
end_addr = start_addr + 'hfffff -'h1;//use 1 kb range
$display(“samir debug - start_addr=%0h end_addr=%0h”,start_addr,end_addr);
addr = std::randomize(addr1) with { addr1 <= end_addr ; addr1 >= start_addr ;} ;
$display(“samir debug - addr is %0h”,addr);
endtask

In reply to samir singh:

Please use code tags in the future to make your code more readable.

Why do you need two separate variables: a rand class member addr AND an automatic task variable addr1? Which by the way is not legal to be declared as rand. Only class members can be declared as rand.

Why do you continue to use

addr = std::randomize(addr1)

What do you expect to happen to addr?

In reply to dave_59:

hi dave,

i want to get the value of addr between start_addr and end_addr.
can’t i get it by using std::randomize()??
i declared automatic task variable addr1 following the syntax mentioned in sv lrm.
can you please help me with the appropriate syntax that would work for the same.

intent :
i just want to get a random address between start_addr and end_addr using std::randomize()

thanks,
samir

In reply to samir singh:

Please answer my questions:

Why do you need both addr and addr1 variables?

Maybe you want

addr = $urandom_range(start_addr,end_addr);

In reply to dave_59:

hi dave,
thank you for the solution.
i was using addr and addr1 as i was not sure if i can use the below code for randomization.

**

addr = std::randomize(addr) with { addr <= end_addr ; addr >= start_addr ;} ;

**

the solution provided by you is fine and that is working but i wanted to used std::randomize().
please let me know if i can use std::randomize() over here or it has some specific use??

In reply to samir singh:

With the constraints you had you can use $urandom_range or std::randomize().
For complex randomization you should use std::randomize().

Also, The code which you wrote will assign 0/1 to addr variable because you are assigning the return value of std::randomize() function to addr.

In reply to Naven8:

thanks naven.