- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As we all know there is a system function $random in Verilog, which can be used to generate the random numbers. I used it in my simulation and call $random() 5 times, then I found each time I simulated, the 10 numbers generated by $random() are always same, I mean e.g.:
The 1st simulation: 1 3 5 6 8 The 2nd simulation: 1 3 5 6 8 So it means although in once simulation, it looks like the random numbers are genrated, but in different simulation, these 5 numbers are always same. I guess this is because $random() needs a seed. But how can I generate a seed in Verilog? Or how can I generate random numbers that change simulation by simulation? Thanks very much.Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Verilog behaves this way so if you find a bug, you can repeat the simulation using the exact same set of values and see if you fix eliminates the bug.
You should call $urandom or $urandom_range(minval,maxval) instead of $random. When you simulate, you can provide a seed using a command switch. In ModelSim/Questa, the switch is -sv_seed random. It will display the random seed used for the simulation so you can repeat it with -sv_seed nnnn.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Verilog behaves this way so if you find a bug, you can repeat the simulation using the exact same set of values and see if you fix eliminates the bug. You should call $urandom or $urandom_range(minval,maxval) instead of $random. When you simulate, you can provide a seed using a command switch. In ModelSim/Questa, the switch is -sv_seed random. It will display the random seed used for the simulation so you can repeat it with -sv_seed nnnn. --- Quote End --- Thanks for reply, dave. What is main difference between $urandom and $random? The seed? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, the initial seed, and the fact that each thread (initial/always block) has an independent seed. $random has only one implicit global seed. See section 18.14 random stability of the 1800-2012 LRM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Yes, the initial seed, and the fact that each thread (initial/always block) has an independent seed. $random has only one implicit global seed. See section 18.14 random stability of the 1800-2012 LRM --- Quote End --- Thanks very much, dave.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page