This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

random delay .!!

Hi ..

I need help regarding writing a C code for a random delay that its duration is within 0.2 - 0.8 miliSeconds?

Parents
  • A pseudorandom generator should always be seeded before first use (unless maybe if the output is used for regression testing).

    If you have 100 units that gets power at the same time, several of them may read the same timer value and use as seed. So, all would generate the same sequence of random numbers, and may get into very long sequences of deadlock with each other.

    That is why I prefer to not use any pseudorandom number generator for breaking ties. Not using a pseudorandom number generator means that there are no need for one intiial seed. Each and every request for random data will instead be based on continuously generated randomnes. Reading a highspeed timer is one way of doing this. Mixing the current timer value with timestamps and data values from received serial, USB and/or Ethernet data is a more complicated (but hopefully better) way of doing it.

Reply
  • A pseudorandom generator should always be seeded before first use (unless maybe if the output is used for regression testing).

    If you have 100 units that gets power at the same time, several of them may read the same timer value and use as seed. So, all would generate the same sequence of random numbers, and may get into very long sequences of deadlock with each other.

    That is why I prefer to not use any pseudorandom number generator for breaking ties. Not using a pseudorandom number generator means that there are no need for one intiial seed. Each and every request for random data will instead be based on continuously generated randomnes. Reading a highspeed timer is one way of doing this. Mixing the current timer value with timestamps and data values from received serial, USB and/or Ethernet data is a more complicated (but hopefully better) way of doing it.

Children
No data