Quick HP42S question
05-25-2020, 05:09 PM
Post: #14
 Albert Chan Senior Member Posts: 2,682 Joined: Jul 2018
RE: Quick HP42S question
(05-25-2020 02:35 PM)Valentin Albillo Wrote:              N     Nth random number
---------------------------------
1     0.731362440213
10     0.723555832003
100     0.056136887198
1 000     0.411709251980
10 000     0.823130519800
100 000     0.935105198000
1 000 000     0.831051980000
10 000 000     0.410519800000
100 000 000     0.205198000000

Not very random-looking, methinks, and that many trailing zeros ...

This apply to any LCG RNG: seed * a mod m

k-th random number = seed * a^k mod m

If k = order(a,m), we have a^k mod m = 1
If k | order(a,m), we expect a non-random pattern for s = a^k mod m

Example, to reproduce above numbers:

>>> a, m = 2851130928467, 10**15
>>> seed = 10**14 + 11﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ # seed for RANDOMIZE 1
>>> for i in xrange(9): ﻿ ﻿ ﻿ ﻿ ﻿ ﻿# note: order(a,m) = 5E13
... ﻿ ﻿ ﻿ ﻿ n = 10 ** i ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿# note: n | order(a,m)
... ﻿ ﻿ ﻿ ﻿ s = pow(a,n,m)
... ﻿ ﻿ ﻿ ﻿ print '%-9d %015d %015d' % (n, s, s*seed % m)
...
1﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 002851130928467﻿ ﻿ 731362440213137
10﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 165777802909449﻿ ﻿ 723555832003939
100﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 268739717018001﻿ ﻿ 056136887198011
1000﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 573791750180001﻿ ﻿ 411709251980011
10000﻿ ﻿ ﻿ ﻿ ﻿ 429375501800001﻿ ﻿ 823130519800011
100000﻿ ﻿ ﻿ ﻿ 439555018000001﻿ ﻿ 935105198000011
1000000﻿ ﻿ ﻿ 975550180000001﻿ ﻿ 831051980000011
10000000﻿ ﻿ 755501800000001﻿ ﻿ 410519800000011
100000000 555018000000001﻿ ﻿ 205198000000011

Most significant digits are more random than least siginificant digits.
Thus, last 3 digits were chopped off, to produce RND()
 « Next Oldest | Next Newest »

 Messages In This Thread Quick HP42S question - Valentin Albillo - 05-24-2020, 11:31 PM RE: Quick HP42S question - ijabbott - 05-24-2020, 11:36 PM RE: Quick HP42S question - Thomas Okken - 05-24-2020, 11:37 PM RE: Quick HP42S question - Valentin Albillo - 05-25-2020, 12:17 AM RE: Quick HP42S question - Thomas Okken - 05-25-2020, 12:29 AM RE: Quick HP42S question - Joe Horn - 05-25-2020, 02:41 AM RE: Quick HP42S question - ijabbott - 05-25-2020, 09:33 AM RE: Quick HP42S question - Gerald H - 05-25-2020, 05:30 AM RE: Quick HP42S question - ijabbott - 05-25-2020, 08:57 AM RE: Quick HP42S question - Werner - 05-25-2020, 06:40 AM RE: Quick HP42S question - J-F Garnier - 05-25-2020, 09:06 AM RE: Quick HP42S question - Valentin Albillo - 05-25-2020, 02:35 PM RE: Quick HP42S question - Albert Chan - 05-25-2020 05:09 PM RE: Quick HP42S question - Joe Horn - 05-25-2020, 07:22 AM

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