-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.v
More file actions
43 lines (41 loc) · 1.1 KB
/
Copy pathrandom.v
File metadata and controls
43 lines (41 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 15:53:43 01/12/2018
// Design Name:
// Module Name: random
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`timescale 1ns / 1ps
module random(
input clk,
input rst,
output reg [4:0] data
);
reg [4:0] data_next;
always @(posedge clk) begin //利用线性反馈移位寄存器的原理生成随机数
data_next[4] = data[4]^data[1]; //本模块采用的线性函数为异或。
data_next[3] = data[3]^data[0];
data_next[2] = data[2]^data_next[4];
data_next[1] = data[1]^data_next[3];
data_next[0] = data[0]^data_next[2];
end
always @(posedge clk or posedge rst) begin
if(rst) //复位键给出初始值
data <= 5'h1f;
else
data <= data_next; //在每个clk上升沿刷新随机数
end
endmodule