More pseudo random number generators for calculators
07-09-2020, 07:35 PM
Post: #6
 Namir Senior Member Posts: 823 Joined: Dec 2013
RE: More pseudo random number generators for calculators
(07-09-2020 11:19 AM)Albert Chan Wrote:  Hi, Namir

Some algorithms you tested might get stuck, even with non-zero fractional part guess

Example, say with 12 digits calculator:

r = 0.999 999 999
r = frac(997/r) ﻿ ﻿ ﻿ ﻿ → r = frac(997.000000 997000000 997000000 ...) = .000 000 997
r = frac(997/r) ﻿ ﻿ ﻿ ﻿ → r = 0
r = frac(997/r) ﻿ ﻿ ﻿ ﻿ → r = NaN

To avoid rounding errrors like above, multiply based versions is safer.
With 15 digits internal precision, and 3 digits factor k, r = frac(k*r) is guaranteed exact.

This may be why baseline use r = frac(997*r)

You certainly have a point. However, in each "run" I would generate a billion random numbers and I never had a runtime error. So the likelihood of getting a random number very close to 1 is small. Of course dealing with floating point number depends on many aspects of the software being used.
 « Next Oldest | Next Newest »

 Messages In This Thread More pseudo random number generators for calculators - Namir - 07-08-2020, 02:19 PM RE: More pseudo random number generators for calculators - Erik-M - 07-08-2020, 07:51 PM RE: More pseudo random number generators for calculators - ttw - 07-09-2020, 03:45 AM RE: More pseudo random number generators for calculators - Namir - 07-10-2020, 11:25 PM RE: More pseudo random number generators for calculators - Namir - 07-15-2020, 06:12 AM RE: More pseudo random number generators for calculators - Albert Chan - 07-09-2020, 11:19 AM RE: More pseudo random number generators for calculators - Namir - 07-09-2020 07:35 PM RE: More pseudo random number generators for calculators - Gene - 07-09-2020, 09:15 PM RE: More pseudo random number generators for calculators - Namir - 07-09-2020, 09:45 PM RE: More pseudo random number generators for calculators - ttw - 07-09-2020, 01:42 PM RE: More pseudo random number generators for calculators - ttw - 07-13-2020, 03:00 PM

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