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 44 45 46 47 48 49 50 51 52
|
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0
module t;
process p;
integer seed;
string state;
int a;
int b;
initial begin
p = process::self();
// Test setting RNG state with state string
state = p.get_randstate();
p.set_randstate(state);
a = $random;
p.set_randstate(state);
b = $random;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
// Test the same with $urandom
state = p.get_randstate();
p.set_randstate(state);
a = $urandom;
p.set_randstate(state);
b = $urandom;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
// Test if the results repeat after the state is reset
state = p.get_randstate();
for (int i = 0; i < 10; i++)
$random;
a = $random;
// Now reset the state and take 11th result again
p.set_randstate(state);
for (int i = 0; i < 10; i++)
$random;
b = $random;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule
|