$system returns & fully random seeds - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

208


21
 
1
module Top;
2
  
3
  function void set_true_random_seed(string file, int line);
4
    integer fd, cnt, seed;
5
    std::process p;
6
    p = process::self();
7
    $system( "head -4 /dev/urandom | od -N 4 -D -A n | awk '{print $1}' > seed.txt" );
8
    fd = $fopen( "seed.txt", "r" );
9
    cnt = $fscanf( fd, "%d", seed );
10
    $fclose( fd );
11
    $display( "%0t %s:%0d ",$time, file, line, "Set seed=%0d", seed );
12
    p.srandom(seed);
13
  endfunction
14
  
15
  initial begin
16
    $display( "$system=%0d", $system( "perl -e 'print q{Pass };exit 0;'" ) );
17
    $display( "$system=%0d", $system( "perl -e 'print q{Fail };exit 1;'" ) );
18
    
19
    set_true_random_seed(`__FILE__,`__LINE__);
20
  end
21
endmodule
xxxxxxxxxx
1
 
1
// Code your design here
2
1046 views and 0 likes     
 
Illustrates how to use $system and provides a function that will produce a fully random seed. Note: It is important to print the seed value so that you can later reproduce a simulation if it happens to fail. The file and line inputs are in case you call this multiple times from multiple places. Note that it is not very fast, so you don't want to call it except to establish initial seeding at time zero.

Illustrates how to use $system and provides a function that will produce a fully random seed. Note: It is important to print the seed value so that you can later reproduce a simulation if it happens to fail. The file and line inputs are in case you call this multiple times from multiple places. Note that it is not very fast, so you don't want to call it except to establish initial seeding at time zero.

1770:0