How Rand is RAND?

20 views

TranslucentAmoebae

Oct 5, 2006, 5:25:17 PM10/5/06
to
Someone posted awhile ago; asking if the digits in a RAND fraction are
themselves Random,
and i think that this little program below will suggest quite the
opposite...
( There is an amazing wonderland of complexity in each of RAND's
fractional digits...!!! )

'Statc'
<< RAND RAND DUP2 > :: SWAP IFT
RAND RAND DUP2 > :: SWAP IFT
4 DUPN XRNG YRNG
{ #0d #0d } PX->C { #1d #1d } PX->C - V->
-> a b g h xx yy
<<
a b FOR y
g h FOR x
--Function goes here--
IP 2 MOD x y R->C SWAP :: PIXON :: DROP IFTE
xx STEP
yy STEP
>> >>

'Pick'
<< OVER SIGN 3 ROLLD OVER MANT 10 /
ROT XPON ->STR + 2 12 SUB DUP SUB DUP "" ==
<< DROP "0" >> IFT OBJ-> * >>

Functions ( Various Possibilities )
a) x INV y INV + FP RDZ RAND 100 *
b) x y + FP RDZ RAND 4 Pick
c) x RDZ RAND y INV * FP 100 *
z) Try your own...

Each plot takes about 15_min's on an HP48gx
Even though the plot may seem to be progressing towards either
randomality or high structure, i would like to urge you to let it
finish, because they often flip tangentally half way through...???
What does this mean...???
One thing, if the PPAR was just a tiny bit off one way or the other,
all the numbers being considered for PIXON or not would be different,
suggesting that the plot would be wildly different for each tiny
variation, But this is not so... each tiny variation produced pretty
much the same structural pattern, suggesting that not only does the
RAND fractions have structure, but the Pick subroutine shows that there
is a unique structure within each place value of that RAND
fraction...!!!
???

John H Meyers

Oct 6, 2006, 1:26:18 AM10/6/06
to
On Thu, 05 Oct 2006 16:25:17 -0500, TA wrote:

| \<< RAND RAND DUP2 > :: SWAP IFT

| RAND RAND DUP2 > :: SWAP IFT

| 4 DUPN XRNG YRNG ...

You are setting the graphing range to a random (and smaller)
subset of the full range of RAND...

| ...

| --Function goes here--
| IP 2 MOD x y R->C SWAP :: PIXON :: DROP IFTE

| ...

| Functions ( Various Possibilities )
| a) x INV y INV + FP RDZ RAND 100 *
| b) x y + FP RDZ RAND 4 Pick
| c) x RDZ RAND y INV * FP 100 *
| z) Try your own...

RDZ sets the random seed again,
which does not continue the original sequence,
but starts a new sequence; it seems no surprise
that the next output(s) after RDZ are related
to the input of RDZ; at any rate,
this does not plot long-term results
of an uninterrupted RAND sequence.

> there is a unique structure within each place value of that RAND fraction!!!

A multiplicative (or linear) congruence generator
has lots of structure in its rightmost digit(s),
less so in its leftmost digits (or full value,
which is the only way it's supposed to be used);
as long as you also don't multiply it by huge values
(e.g. to pick individual "random throws" of one-billion-sided dice :)
it will work well enough for whatever can be calculated
in reasonable time on this calculator.

Speaking of re-using code,
the current RAND generator hasn't changed
between the HP42S all the way to the HP50G;
perhaps it's older still in HP calcs (JKH?)

TA's similar investigations into RAND go way back, e.g.:
[Bob Wheeler's initial post starting that thread is missing,
but is later quoted; Bob also suggests some better RAND functions]

For further amusement, how about these:
5.13684117130E47 RDZ RAND RAND RAND RAND ==> .000000000000001
4.39513938817E18 RDZ RAND RAND ==> .999999999999999
On HP49/50, backup user memory and then very carefully type
(the "string" has exactly 14 leading zeros):
#80EE1h "000000000000005" #100010h LIBEVAL
then try RAND, RAND, RAND, ...

And Joe Horn has noted this:
| Do 8, square root, RDZ. Then:
| 3*RAND +8*RAND -5*RAND -6*RAND +7*RAND -8*RAND -9*RAND -3*RAND = 1 [exactly]

So much for a reply to a randomly-selected post ;-)

Joe Horn

Oct 6, 2006, 12:33:57 PM10/6/06
to
John H Meyers wrote:

> Speaking of re-using code,
> the current RAND generator hasn't changed
> between the HP42S all the way to the HP50G;
> perhaps it's older still in HP calcs (JKH?)

It was first written for either the HP-71B or HP-27S, but I cannot
determine which. Here's why.

HP made the entire original source code for the HP-71B's operating
system, including comments, available to hoi polloi. The header on the
source code for %RAN includes a funny but cryptic credit:

** Name: %RAN
**
** Abstract: Returns the next element of a pseudo-random
** number sequence. Updates RNSEED.
**
** Stack: --> %
**
** Exceptions: none
**
** Author: All inquiries may be addressed to the late great
** Homer Russel, wherever he is.

Much of the HP48's internal math code was copied from the HP-71B, but
some was also copied from the HP-27S. The source code does not say
whether Homer (doh!) originally wrote the RANDOMIZE and RAND commands
for the 27S or 71B. The 71B came out before the 27S, but their project
development overlapped, so I dunno for sure.

-Joe-

TranslucentAmoebae

Oct 10, 2006, 3:04:42 PM10/10/06
to

TranslucentAmoebae wrote:
> Someone posted awhile ago; asking if the digits in a RAND fraction are
> themselves Random,
> and i think that this little program below will suggest quite the
> opposite...
> ( There is an amazing wonderland of complexity in each of RAND's
> fractional digits...!!! )
>
> 'Statc'
> << RAND RAND DUP2 > :: SWAP IFT
> RAND RAND DUP2 > :: SWAP IFT
> 4 DUPN XRNG YRNG
> { #0d #0d } PX->C { #1d #1d } PX->C - V->
> -> a b g h xx yy
Oops...!!!
That should be...
{ #1d #0d } PX->C { #0d #1d } PX->C - V->
i have a subroutine that does this, and i replaced it with the code
from MEMORY...!!!
Sssooorrrrrryyy...!!!