In abounding applications, the ambit of assortment ethics may be altered for anniversary run of the program, or may change forth the aforementioned run (for instance, back a assortment table needs to be expanded). In those situations, one needs a assortment action which
takes two parameters—the ascribe abstracts z, and the cardinal n of accustomed assortment values
.
A accepted band-aid is to compute a anchored assortment action with a actual ample ambit (say, 0 to 232−1), bisect the aftereffect by n, and use the division's remainder. If n is itself a ability of 2, this can be done by bit appearance and bit shifting. Back this access is used, the assortment action charge be called so that the aftereffect has adequately compatible administration amid 0 and n−1, for any n that may action in the application. Depending on the function, the butt may be compatible alone for assertive n, e.g. odd or prime numbers
.
It is accessible to relax the brake of the table admeasurement actuality a ability of 2 and not accepting to accomplish any modulo, butt or analysis operation -as these operation are advised computational cher in some contexts. For example, back n is decidedly beneath than 2b activate with a bogus accidental cardinal architect (PRNG) action P(key), compatible on the breach 0, 2b−1. Consider the arrangement q = 2b / n. Now the assortment action can be apparent as the amount of P(key) / q. Rearranging the adding and replacing the 2b-division by bit alive appropriate (>>) b times you end up with assortment action n * P(key) >> b.
takes two parameters—the ascribe abstracts z, and the cardinal n of accustomed assortment values
.
A accepted band-aid is to compute a anchored assortment action with a actual ample ambit (say, 0 to 232−1), bisect the aftereffect by n, and use the division's remainder. If n is itself a ability of 2, this can be done by bit appearance and bit shifting. Back this access is used, the assortment action charge be called so that the aftereffect has adequately compatible administration amid 0 and n−1, for any n that may action in the application. Depending on the function, the butt may be compatible alone for assertive n, e.g. odd or prime numbers
.
It is accessible to relax the brake of the table admeasurement actuality a ability of 2 and not accepting to accomplish any modulo, butt or analysis operation -as these operation are advised computational cher in some contexts. For example, back n is decidedly beneath than 2b activate with a bogus accidental cardinal architect (PRNG) action P(key), compatible on the breach 0, 2b−1. Consider the arrangement q = 2b / n. Now the assortment action can be apparent as the amount of P(key) / q. Rearranging the adding and replacing the 2b-division by bit alive appropriate (>>) b times you end up with assortment action n * P(key) >> b.
No comments:
Post a Comment