HP 12C Random Integer Number Generator
|
11-20-2017, 01:45 PM
(This post was last modified: 11-20-2017 02:13 PM by Dieter.)
Post: #5
|
|||
|
|||
RE: HP 12C Random Integer Number Generator
(11-20-2017 04:46 AM)Gamo Wrote: On 11C and 15C both have dedicated RAN# function that very easy to program random 6 digits number using RAN# With a built-in PRNG of course things are easy. However, there is a numeric pitfall. Since the RAN# function may return results as large as 0,9999999999 (i.e. 1–10–10) the intermediate result of r · n may round to n and the final result then is n+1. Example: Suppose you want random numbers between1 and 2000. 0,9999999999 · 2000 + 1 = 2001,000000 Or simply think of generating numbers between 1 and 3, e.g. for a game: 0,9999999999 · 3 + 1 = 4,000000000 This can be avoided by removing the final digit of the random number (and, just to be sure, adding 1 after the INT truncation): Code: RAN# ...or, faster and shorter, simply... Code: RAN# Anyway, the mentioned problem does not occur for your special case n = 999999, so you can leave your program as it is. ;-) Also the well known and simple PNRG r := frac[(r+pi)²] is not affected as it generates numbers with (mostly) 8 and (sometimes) 9 decimals on a 10-digit calculator. Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
HP 12C Random Integer Number Generator - Gamo - 11-16-2017, 04:58 AM
RE: HP 12C Random Integer Number Generator - Dieter - 11-16-2017, 08:06 AM
RE: HP 12C Random Integer Number Generator - Dieter - 11-19-2017, 09:23 PM
RE: HP 12C Random Integer Number Generator - Gamo - 11-20-2017, 04:46 AM
RE: HP 12C Random Integer Number Generator - Dieter - 11-20-2017 01:45 PM
RE: HP 12C Random Integer Number Generator - Gamo - 11-21-2017, 05:13 AM
RE: HP 12C Random Integer Number Generator - SlideRule - 11-04-2018, 04:03 PM
RE: HP 12C Random Integer Number Generator - Dieter - 11-04-2018, 06:02 PM
|
User(s) browsing this thread: 1 Guest(s)