(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
 Albert Chan Senior Member Posts: 2,556 Joined: Jul 2018
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 »

 Messages In This Thread (11C) Random Prime Number Generator - Gamo - 10-20-2018, 01:08 PM RE: (11C) Random Prime Number Generator - Dieter - 10-20-2018, 07:08 PM RE: (11C) Random Prime Number Generator - Gamo - 10-21-2018, 03:22 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 05:09 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 08:45 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 04:41 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-21-2018, 01:31 PM RE: (11C) Random Prime Number Generator - John Keith - 10-21-2018, 01:52 PM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 11:03 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 05:20 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-21-2018, 07:02 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-22-2018 01:02 AM RE: (11C) Random Prime Number Generator - Gene - 10-21-2018, 07:47 PM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 09:09 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 08:47 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 09:03 PM RE: (11C) Random Prime Number Generator - Gene - 10-21-2018, 10:02 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 03:46 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 04:10 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 09:11 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 09:22 AM RE: (11C) Random Prime Number Generator - Gamo - 10-22-2018, 10:32 AM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 11:23 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 12:28 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 12:31 PM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 06:43 PM

User(s) browsing this thread: 1 Guest(s)