In reply to chr_sue:
I believe the original question is about the choice between using if or assert statements to check the result of calling randomize().
Actually, my problem with the original code is it does not call umm_error or umm_fatal on failure. The UVM methodology requires all errors be trapped by a UVM_ERROR or greater severity. This is needed for managing regressions properly and for catching expected errors with negative tests.
Many people ignore the warnings they get when calling randomize() without checking the result (Some tools do not even generate a warning). So their test improperly carries on, leaving their random variables unmodified.
Using an immediate assertion was a quick and easy way of generating an error. It was unfortunate that SystemVerilog later added the $assertoff functionality to immediate assertions and had it not evaluate the condition. It should have just turned off the checking.
But now that the UVM requires calling `umm_error when failing, it’s a few characters less typing to use the if statement and you get the same functionality as the assert without the risk of having it turned off,