Post Reply 
An unexpected result involving sums of random numbers
02-28-2023, 06:41 PM
Post: #1
An unexpected result involving sums of random numbers
How many random numbers in the interval [0, 1) are required to add up to 1 or higher, in average?

The following HP-42S and HP-15C programs might give an answer to this question in under one minute on the physical calculators (with some cheating due to the choice of seeds and number of results equal or greater than one), or in reasonable on Free42 and other simulators with a large number of results, regardless of the seeds.

HP-42S:

Code:

00 { 36-Byte Prgm }
01▸LBL "X"
02 STO 00
03 0
04 STO 01
05 SIGN
06▸LBL 00
07 RAN
08▸LBL 01
09 X<>Y
10 STO+ 01
11 X<>Y
12 RAN
13 +
14 X<Y?
15 GTO 01
16 R↓
17 DSE ST Y
18 GTO 00
19 RCL 01
20 RCL+ 00
21 RCL÷ 00
22 END

6 SEED 252 XEQ “X” -> ______________ (55.5 seconds on the real calculator)

Code:

00 { 40-Byte Prgm }
01▸LBL "X"
02 STO 00
03 1
04 SIGN
05▸LBL 00
06 RAN
07▸LBL 01
08 RCL- ST L
09 RAN
10 -
11 1
12 STO+ ST Z
13 +
14 X>0?
15 GTO 01
16 R↓
17 DSE ST Y
18 GTO 00
19 DSE ST X
20 RCL+ 00
21 RCL÷ 00
22 END

67 SEED 252 XEQ “X” -> ______________ (63 seconds on the real calculator)

HP-15C:

Code:

   001-     42 21 11   f LBL A
   002-        44 25     STO I
   003-        44  0     STO 0
   004-            0     0
   005-        44  1     STO 1
   006-        42  0   f x!        ; 1
   007-     42 21  0   f LBL 0
   008-        42 36   f RAN #
   009-     42 21  1   f LBL 1
   010-           34     x<>y
   011-     44 40  1     STO+ 1
   012-           34     x<>y
   013-        42 36   f RAN#
   014-           40     +
   015-     43 30  8   g TEST 8    ; x<y
   016-        22  1     GTO 1
   017-           33     Rv
   018-     42  5 25   f DSE I
   019-        22  0     GTO 0
   020-        45  1     RCL 1
   021-     45 40  0     RCL+ 0
   022-     45 10  0     RCL/ 0
   023-        43 32   g RTN

6 STO RAN# 32 f A -> ______________ (55 seconds on the real HP-15C)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
An unexpected result involving sums of random numbers - Gerson W. Barbosa - 02-28-2023 06:41 PM



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