In this laboratory, for this lab you are required to design an 8-bit pseudo-rand
ID: 2081390 • Letter: I
Question
In this laboratory, for this lab you are required to design an 8-bit pseudo-random number generator. A pseudorandom number generator is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG generated sequence is not truly random, because it is completely determined by a relatively small set of initial values. (Source - Wikipedia). Your component should have the below input and output pins. Input pins: - clock, Reset. 8 bit Output: - q.Explanation / Answer
The verilog code for the number generator is :
module prng(clock,reset,q);
input clock,reset;
output [7:0] q;
// if reset==1 the output will be set to 8'b00000001
// else q[7] will be assigned to q[0]^q[2]^q[3]^q[4] and rest of the bits will be shifted right
reg [7:0] seq;
assign q=seq;
always@(posedge(clock))begin
if(reset)begin
seq<=8'b00000001;
end
else begin
seq[7]<=seq[0]^seq[2]^seq[3]^seq[4];
seq[6:0]<=seq[7:1];
end
end
endmodule
Testbench for checking correctness of the code(upto 20 sequences):
module prng_test();
reg clock;
reg reset;
wire [7:0] q;
prng M1(clock,reset,q);
always #5 clock=~clock;
always #10 $display("the sequence is %b",q);
initial #200 $finish;
initial begin
clock=0;
reset=1;
#6 reset=0;
end
endmodule
The output pattern obtained for first 20 sequences is :
the sequence is 00000001
the sequence is 10000000
the sequence is 01000000
the sequence is 00100000
the sequence is 00010000
the sequence is 10001000
the sequence is 11000100
the sequence is 11100010
the sequence is 01110001
the sequence is 00111000
the sequence is 00011100
the sequence is 10001110
the sequence is 01000111
the sequence is 00100011
the sequence is 10010001
the sequence is 01001000
the sequence is 10100100
the sequence is 11010010
the sequence is 11101001
the sequence is 01110100
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.