Afficher un message
Vieux 27/05/2008, 20h42   #16
Eric Sosman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Getting a random number

inuy4sha wrote:
> [...]
> I need this random number to generate random backoff idle periods in a
> wireless network


Then you can probably make do with a fairly weak notion
of "randomness:" Your only concern is making sure that all
the network participants don't back off in lock-step with
each other and re-collide. You could probably get away with
not calling srand() at all and just using rand() with its
default seed, if the participating stations join the network
at different moments and/or see different histories of when
they need to back off.

If that's too simplistic for your peace of mind, then
seeding with the wall-clock time probably isn't enough to let
you rest easy, either. After all, the "current time of day"
as reported by N different computers is likely to be highly
correlated! On most systems, time() has a precision of one
second (C does not require this, but it's common practice),
so if the various clocks are all within five seconds, say, of
some external time standard there will be fewer than a dozen
different srand() seeds ...

Perhaps you could just generate and discard a rand() value
every so often, like each time a packet arrives. If different
stations see different packet streams, their rand() sequences
will get out of step even if they all started identically, and
that might be good enough.

--
Eric.Sosman@sun.com
  Réponse avec citation
 
Page generated in 0,05724 seconds with 9 queries