+ Post New Thread
Results 1 to 2 of 2
- 16th September 2006, 09:17 #1
- Join Date
- Apr 2006
- 0 / 0
verilog system time
i want to generate a random number in verilog with the system time as the seed.
the normal $random() generates a random value by taking the $time (simulation time) as its seed.
so, how do i get the "system time" in verilog (or) how do i generate random value with system time as its seed.
- 16th September 2006, 09:17
16th October 2009, 17:52 #2
- Join Date
- Nov 2008
- 2 / 2
Re: how to get system time in verilog
I could not find an elegant way, but here's how I did it - a system call to write the current time into a file, then read the file to get the info into verilog. The system call to "date" only works on *NIX - if you are on windows, you'll have to change that. Anyway, here's the code:
Code:integer FP; integer fgetsResult; integer sscanfResult; integer NowInSeconds; reg [8*10:1] str; // call "date" and put out time in seconds since Jan 1, 1970 (when time began, no doubt) // and put the results in a file called "now_in_seconds" $system("date +%s > now_in_seconds"); // open the file for reading FP = $fopen("now_in_seconds","r"); // get a string from the open file - "fgetsResult" should be a 1 - you can test // that for completeness if you'd like fgetsResult = $fgets(str,FP); // convert the string to an integer - "sscanfResult" should also be a 1, and // you can test that, too, sscanfResult = $sscanf(str,"%d",NowInSeconds); // close the file... $fclose(FP); // closes the file // use the number as a seed... process::self.srandom(NowInSeconds);
I have run this in "ncverilog" and confirmed it on both Solaris and Linux systems.
2 members found this post helpful.