Jump to content
IGNORED

Can RND ever produce a zero?


senior_falcon

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 GROM@>4F16 No, go on
4F0C : DEC @>834A -1
4F0E : CZ @>834A 0?
4F10 : BS GROM@>4F23 End with 0
4F12 : BR GROM@>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.

 

 

 

 

Link to comment
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.

  • Haha 1
Link to comment
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 ? .

Link to comment
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

  • Like 1
Link to comment
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
[0911] A2AD 42,B9           BR   NRND3     
[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
Added Text.
Link to comment
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
Link to comment
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.)

  • Like 1
Link to comment
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

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...