Why void casting when randomizing class variables?

Hello,

I studying randomize() of variables within a class. I read that the void casting of randomize() hides the result status of randomize().
Anyway, the conclusion is that it is desirable to process the result of randomize() through an if statement or an assert statement.

I have questions.

  1. What is the meaning of randomize’s void casting if the result of randomize is not needed? In this case, what is the difference between void casting and non-void casting?

  2. Usually, randomize will be handled with if or assert statement, but in which case is casting the result of randomize() to void type?

Thank you for your reply.

In reply to jh_veryveri:

  1. Casting the return value of a function to void explicitly tells the compiler / simulator that you are discarding the value. Some compilers / simulators may throw a warning if it’s not cast to void.

  2. You should always check the return value of randomize, even on “obvious” randomizations that you know can’t fail. A macro can help make things easier.

In reply to sbellock:

Thanks you!!

Have a nice day!