Query regd file handling in System verilog

In reply to ArjunNag:

In your code, txn_count as default is 0, the loop won’t be executed. Shall you have txn_count to be randomized with “rand” keyword or will you assign a value to it larger than 0 already?

If txn_count is larger than 0, then the following code will work to have Opcodes, price_rand, OrderId_rand get value from the text file. Here, $fopen() and $fclose() used.

But in your code, after you have gotten value from the text file, I don’t see you use them as part of the transaction. I think codes need to be refined to fit for purpose more.


    for (int i=0;i<txn_count;i++) begin : file_block
      file = $fopen("rand_Inputs_generator.txt","r");
      while (!$feof(file)) begin
        r = $fscanf(file, " %d %d %d", Opcodes, price_rand, OrderId_rand);
        $display(" %d %d %d", Opcodes, price_rand, OrderId_rand);
      end // while not EOF
      $fclose(file);
    end