Help with the constraint

Hi,
I need to generate reads and writes in a sequence. The number of reads and writes are fixed values, decided based on the test. Lets call them num_rd, num_wr.
I need to randomly choose whether I want to send a read or write.

For this I am using a 1bit variable “m_send_read”.
The code looks like:

for (int i = 0; i < num_rd + num_wr; i++) begin
if (!randomize(m_send_read)
   `uvm_fatal(get_name(), "Failed to randomize m_send_read")
if (m_send_read)
    send_read_txn();
else
    send_write_txn();
end

For m_send_read, I am writing the below constraint:

  constraint c_send_read {
    m_send_read dist {1 := num_rd, 0 := num_wr};
  }

The problem is that with the above constraint, I will not get exact numbers of read and writes.
For eg, If I need to send 100 read and 500 writes, I get something like 97 reads and 503 write.

Is there a way to get fixed number of transactions randomly distribute?

In reply to none_available:

Does it make a real difference if you send 97 reads/503 writes vs. 100 reads/500 writes?

One issue with people new to constrained random verification is that they want to follow directed test methodologies which limit the flexibility of CRV.

Constraints should only be used to constrain configurations and data generation to valid sets. You should minimize the use of constraints to create specific transaction streams. In other words, you should just randomize the transaction and let the randomness of the tool interleave the reads and writes. This method will generate scenarios that you haven’t envisioned.

In reply to cgales:

Thanks cgales.
I agree with your argument.

I would like to explain why I need 100/500 Vs 97/503.
I simplified the problem statement, to focus on the constraint question. The test actually sends special transactions and requests (request can be read or write). There are multiple clients and it is necessary that all clients send the special transactions in the same order and send an equal number of them.
If all clients don’t send the all the special transactions, the simulation will hang.

There is no such limitation on the requests. I agree that I can use the above constraint and keep on sends transactions (special transactions and requests) till the required number of special transactions are sent and that will work (most likely what I would end up doing :) ).

I was just curious to see if there is something that I had not thought of.

In reply to none_available:

The reason you aren’t seeing the exact distribution expected is due to the randomness (by design) of the simulation. If you run multiple simulations with different seeds, you will see an overall general distribution of 5:1. Sometimes more, sometimes less.

I would try and determine why your environment hangs if a different number of sequence items are sent to the different agents. This seems like a significant flaw which should be investigated.

If you want to ensure that the same transactions are sent to each agent, then you should use a virtual sequence to randomize a transaction, clone it as many times as necessary, then send each cloned item to each agent.

Thanks cgales,

I believe I got answer to my query :).