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
  • Even if a semirandom event is used to initialize a pseudorandom generator, you can be unlucky enough to get the same seed and then get into a permanent deadlock.
    yes, in one case of 65536 squared (if you use all the bits). Anyhow why would you seed the pseudo, I just use the value read from the timer.

    A solution that the whole time looks for new randomizing events have a lot less probability of deadlocks (as long as there are devices or events that can be used/abused for randomness).
    I had the same thought and am doing it that way. Now discussing it, I doubt it will make any difference whether you read it once or repeatedly.

    Erik

Reply
  • Even if a semirandom event is used to initialize a pseudorandom generator, you can be unlucky enough to get the same seed and then get into a permanent deadlock.
    yes, in one case of 65536 squared (if you use all the bits). Anyhow why would you seed the pseudo, I just use the value read from the timer.

    A solution that the whole time looks for new randomizing events have a lot less probability of deadlocks (as long as there are devices or events that can be used/abused for randomness).
    I had the same thought and am doing it that way. Now discussing it, I doubt it will make any difference whether you read it once or repeatedly.

    Erik

Children
  • 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.