Can RND ever produce a zero?

Recommended Posts

According to TI: "RND The random number generated will be greater than or equal to zero and less than one."

Here is some of the code for the random number generator (from INTERN):

```Basic RND:
4F00 : ST @>834A,>3F Exponent
4F03 : ST @>8310,>4B Loop counter
4F06 : RAND >63 till 100
4F08 : CZ @>8378 0?
4F0A : BR [email protected]>4F16 No, go on
4F0C : DEC @>834A -1
4F0E : CZ @>834A 0?
4F10 : BS [email protected]>4F23 End with 0
4F12 : BR [email protected]>4F06 Go on

```

This part of the code sets the exponent. RAND >63 creates a random integer from 0 to 99 and puts it in >8378. To produce a zero, you have to roll a zero 63 times in a row. The odds of this happening would be about 1 in 1*100^63 or

1 in 1E126.

There were about 2.8 million TI99/4A computers made. Let's assume they were all made in 1982, and that all of them have been creating 100 random numbers a second since the day they were made. We get:

2.8 million*37 years*365 days/year*24 hours/day*60 minutes/hour*60 seconds/minute*100 RND/second which gives:

3.27E17 random numbers.

So the chances of this array of computers having ever produced a zero for a random number is about 3.27E-109

I think we can confidently say that RND has never produced a zero.

Share on other sites

And still...

...I hate it when that happens!

Share on other sites
46 minutes ago, senior_falcon said:

So the chances of this array of computers having ever produced a zero for a random number is about 3.27E-109

I think we can confidently say that RND has never produced a zero.

It will generate a zero five minutes after code that assumes it can't do so is run.

Share on other sites

Indeed.  Observation changes the results of an experiment.

• 1
• 1

Share on other sites
10 hours ago, OLD CS1 said:

Indeed.  Observation changes the results of an experiment.

I know too well. I was "experimenting" as a youngen, totally unaware that i was being watched. Then my dad made his presence known, and yes, it changed the results of my experiment.

What i was experimenting with will be left as a exercise in creative thought for the reader to ponder, and such thoughts are guaranteed to be random 🙂 .

Share on other sites

I ran the TI Basic and RXB 2015 RND on my Classic99 Emulator for 40 hours on SYSTEM MAXIMUM (3.1 Ghz Intel Xeon) without any crashes.

That is rough 1000 times faster than the 3 Mhz TI 9900 maximum speed.

Share on other sites

Did you ever get a zero result?

Share on other sites
On 11/30/2019 at 11:20 PM, senior_falcon said:

According to TI: "RND The random number generated will be greater than or equal to zero and less than one."

. . .

So the chances of this array of computers having ever produced a zero for a random number is about 3.27E-109

I think we can confidently say that RND has never produced a zero.

Though your logic is unassailable, we rarely (ever?) use RND without modification. We are usually looking for a pseudo-random number (PRN) that is an integer with a specified maximum.

The point of RND’s exponent-reduction code is to normalize the floating-point result such that the first digit of the seven-digit, radix-100 (base-100 or centimal) significand (mantissa) is non-zero, i.e.1 – 99 in decimal terms. [See my “RND and RAND: Pseudorandom Number Generation by TI Basic for a complete(?) explanation.] Each consecutive zero produced by the code determining the first digit is considered as part of the result, which, consequently, needs to be adjusted by reducing the exponent until a non-zero digit is produced or, as Harry (@senior_falcon) pointed out, an exceedingly unlikely sixty-third consecutive zero occurs, which is the only condition that will produce a floating-point zero.

But, not to worry—If RND is used to produce 0 ≤ PRN < 100, it takes only one, eminently possible, zero (one decrement of the exponent) to produce PRN = 0 with the following code:

`100 X=INT(RND*100)`

0 ≤ PRN < 1000 requires only that the next call to RAND, after the first zero, produce a digit that is less than decimal 10.

0 ≤ PRN < 10000 would require two consecutive zeros, which is certainly likely in 10000 tries. And, so on ...

...lee

Share on other sites
On 12/1/2019 at 11:06 AM, apersson850 said:

Did you ever get a zero result?

No as the GPL CODE checks if  a zero (0) up to 100 times. i.e. >63 = 99 decimal

```[0905]               ***********************************************************
[0906]               * RXB BASIC RND REPLACEMENT FROM TI BASIC
[0907] A2A3 BE,4A,3F NRND   ST   >3F,@FAC       * Exponent
[0908] A2A6 BE,10,4B        ST   >4B,@VAR5      * Loop counter
[0909] A2A9 02,63    NRND1  RAND >63            * 0?
[0910] A2AB 8E,78           CZ   @RANDOM        * No, go on
[0912] A2AF 92,4A           DEC  @FAC           * 0?
[0913] A2B1 8E,4A           CZ   @FAC           * End with 0
[0914] A2B3 62,C6           BS   NRND4          * Go on
[0915] A2B5 42,A9           BR   NRND1

99/4 GPL-ASSEMBLER (Pass 3) correct                                   PAGE 0016
EQUATES EXEC-359
[0916] A2B7 02,63    NRND2  RAND >63            * Till 100
[0917] A2B9 BC,90,10 NRND3  ST   @RANDOM,*VAR5  * All digits
A2BC 78
[0918] A2BD D6,10,51        CEQ  >51,@VAR5      * Till >8351
[0919] A2C0 62,C8           BS   NRND5
[0920] A2C2 90,10           INC  @VAR5          * Increase loop counter
[0921] A2C4 42,B7           BR   NRND2
[0922] A2C6 86,4B    NRND4  CLR  @FAC1          * Set 0
[0923] A2C8 0F,75    NRND5  XML  CONT
[0924]               ***********************************************************```

If you get a zero it will be extremely rare, so rare that in running the code on my

Xeon 3.1 maxing out Classic99 it never happened in 40 hours.

Edited by RXB

Share on other sites

If you guys are so intent on a fix I could add

CZ @RANDOM

BS repeat loop

I could add this to RXB 2020 for RND in the future.

Nothing is perfect but apparently I have to be...

Share on other sites
35 minutes ago, RXB said:

If you guys are so intent on a fix...

Nothing is perfect but apparently I have to be...

What makes you think this has to be fixed? It was a simple observation that RND statistically will never produce an actual zero.

To put this in perspective, there are estimated to be 10E78 to 10E82 elementary particles in the universe. (Protons, neutrons, electrons, etc.) Last time I looked the universe was a big place.  It is about one billion billion billion times less likely to produce an actual zero with RND than there are particles in the universe!

Edited by senior_falcon

Share on other sites
1 hour ago, senior_falcon said:

To put this in perspective, there are estimated to be 10E78 to 10E82 elementary particles in the universe. (Protons, neutrons, electrons, etc.)

Which is the reason why you cannot write down the Googolplex as a decimal number: You do not have enough particles for all digits.

(Googolplex = 10^Googol, a one with Googol zeros, Googol = 10^100. Mind that Google was named after Googol, and has a domain 1e100.net.)

Share on other sites
4 hours ago, RXB said:

No as the GPL CODE checks if  a zero (0) up to 100 times. i.e. >63 = 99 decimal

Actually, it really will only check for a zero exponent 63 times before it returns a floating-point zero because it starts at >3F (63) and takes exactly 63 DEC instructions to get to zero.

...lee

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.