Re: split the load?

トップ ページ
このメッセージを削除
このメッセージに返信
著者: Warner Losh
日付:  
To: Philip Hazel
CC: exim-users
題目: Re: split the load?
In message
<Pine.SOL.3.95.961122091633.7382A-100000@???> Philip
Hazel writes:
: What is the best *cheap* way of getting a
: random number between 0 and n? Is something like "take the last m bits
: of the time of day modulo (n+1)" good enough for this purpose?

Generally no. When you try to do something like that, you'll find you
get a beat frequency with the system clock update tick. Calling
rand() would likely be a little better and about as exepensive as a
round trip into most kernels. If you happen to have the time just
laying around, this might be acceptible. Either way, the mod in these
operations (unless it is done with a mask of bits) generally
dominates, at least on the hardware of a few years ago.

You are correct that this needn't be perfect. Something close that
spreads the load out is likely sufficient.

Warner