你不应该在SystemVerilog中使用$random,不幸的是,SystemVerilog LRM仍然有使用$random的例子。 你应该使用$urandom,$urandom_range或std::randomize()来获得大多数现代验证环境所需的随机稳定性。
— The system randomization calls, $urandom() and $urandom_range()
— The object and process random seeding method, srandom()
— The object randomization method, randomize()
Testbenches with this feature exhibit more stable RNG behavior in the face of small changes to the user code. Additionally, it enables more precise control over the generation of random values by manually seeding threads and objects.
你可以对简单范围约束使用$urandom_range(Min,Max),或对单个变量使用std :: randomize(myvar)with {simple constraints}。 任何更复杂的东西都应作为一组rand变量和约束放入类对象中。
Random stability
The RNG is localized to threads and objects. Because the sequence of random values returned by a thread or object is independent of the RNG in other threads or objects, this property is called random stability.
Random stability applies to the following:— The system randomization calls, $urandom() and $urandom_range()
— The object and process random seeding method, srandom()
— The object randomization method, randomize()
Testbenches with this feature exhibit more stable RNG behavior in the face of small changes to the user code. Additionally, it enables more precise control over the generation of random values by manually seeding threads and objects.