(11C) Random Prime Number Generator
|
10-22-2018, 01:02 AM
(This post was last modified: 10-22-2018 01:33 AM by Albert Chan.)
Post: #16
|
|||
|
|||
RE: (11C) Random Prime Number Generator
(10-21-2018 04:41 PM)Dieter Wrote: There is another point where the program may not work as intended. The random number can be as large as 0,99999 99999. Multiplying this by 300 with 10-digit precision returns 300 exactly. It seems about 50% of the time, N * RAN# = N rounding bug will not occur. Example: 501 * 0.99999 99999 = 501 - 501/10^10 = 500.9999999 (501 - 1 decimal ULP) Just like the binary case (post 10), error term slightly bigger than 1/2 decimal ULP, thus rounded-up. --> If N mantissa fraction M = N/10^ceil(log10(N)), error term = M decimal ULP --> If M > 1/2, max(N * RAN#) = N - 1 decimal ULP < N So, a simulated dice = INT(6 * RAN#) + 1 is correct. But, coin flipping INT(2 * RAN#) may be wrong. (Unless 2 = standing on edge) Instead, it should remove precision a bit: INT(2 * FRAC(RAN# + 1)) Edit: because of the minus sign in front of error term, rounding rule is half-round-down. Example: 500 * 0.99999 99999 = 500 - 500/10^10 = 500 - 0 = 500 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)