Home.Verilog.Digital Design.Digital Basics.Python.RF Basics.
Previous.Next.
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
FULLCHIPDESIGN
Digital-logic Design...  Dream for many students… start learning front-end…

Legal Disclaimer

PICS
Verilog Tutorial.
Home.
Verilog.
Initial stmts.
IF-ELSE.
Case stms.
Readmemh.
Function.
Testbench.
Binary to Gray.
Clock Crossing.
Half-adder.
Full-adder.
Tristate buffer.
Adder tb.
Counter_enable.
 Blocking.
Operators.
Shift LSR.
Random Nos.
Sync RAM.
Verilog Tutorial.
Verilog testbench to generate random numbers and use of $fdisplay to store it in a text file.
Generating random numbers and $fdisplay in Verilog testbench.
~\Desktop\FCD\downloads\fc_v\random_fc.v.html // Test Bench for generating random numbers
module random_tb ();

integer seed;
integer out;
integer i ;

initial begin
  out = $fopen("rand.vec","w");
  $fdisplay(out, "seed = %h, 1st random number in hexadecimal = 0x%h", seed, $random(seed));
  $fdisplay(out, "seed = %h, 2nd random number in hexadecimal = 0x%h", seed, $random(seed));
  $fdisplay(out, "seed = %h, 3rd random number in hexadecimal = 0x%h", seed, $random(seed));
  $fdisplay(out, "seed = %h, 4th random number in hexadecimal = 0x%h", seed, $random(seed));
  $fdisplay(out, "seed = %h, 5th random number in hexadecimal = 0x%h", seed, $random(seed));
end

endmodule
Contents of the output text ‘rand.vec’ is displayed below.
seed = 23980634, 1st random number in hexadecimal  = 0x12153524
seed = 92153206, 2nd random number in hexadecimal = 0xc0895e81
seed = 40895ccf,  3rd random number in hexadecimal  = 0x8484d609
seed = 0484d4c4, 4th random number in hexadecimal  = 0xb1f05663
seed = 31f054f5,  5th random number in hexadecimal  = 0x06b97b0d
Results are discussed below:-
Return to Verilog Tutorial