Jump to content
IGNORED

Question about RANDOMIZE in XB LOAD file


Recommended Posts

This is probably a novice question but I'm finding that RANDOMIZE no longer produces random results if the program happens to be an XB auto-booting program called LOAD.  Here is a very basic example of what I mean:

 

10 RANDOMIZE

20 PRINT INT(10*RND)+1

 

Obviously this should just print a random number between 1 and 10 and under normal circumstances it works.  That is it at least appears to give a random number every time I run it, which includes if I save it as any file name other than LOAD.  I can reset the computer and load the program (either with OLD or RUN in XB) and it still appears to give a random number each time.  But if it is an auto-booting LOAD program, it just picks 5 every time (well every time on the first boot I mean).  If I modify the program to pick two more random numbers, it always picks 6, then 2.  So now my program always picks 5, 6, 2 when it auto-boots.  Is there something simple here that I'm just missing about LOAD programs?  Thanks

Link to comment
https://forums.atariage.com/topic/341186-question-about-randomize-in-xb-load-file/
Share on other sites

Are you rapidly clicking past the master title page? That used to happen to me - it had become such a rhythm that I was getting the same seed every time. If you sit on the title page a different amount of time, does it change?

 

I usually work around it by generating random numbers when I'm at any "press any key" style prompt. That way you end up at different points in the sequence.

 

  • Like 1
5 hours ago, ruthven said:

This is probably a novice question but I'm finding that RANDOMIZE no longer produces random results if the program happens to be an XB auto-booting program called LOAD.  Here is a very basic example of what I mean:

 

10 RANDOMIZE

20 PRINT INT(10*RND)+1

 

Obviously this should just print a random number between 1 and 10 and under normal circumstances it works.  That is it at least appears to give a random number every time I run it, which includes if I save it as any file name other than LOAD.  I can reset the computer and load the program (either with OLD or RUN in XB) and it still appears to give a random number each time.  But if it is an auto-booting LOAD program, it just picks 5 every time (well every time on the first boot I mean).  If I modify the program to pick two more random numbers, it always picks 6, then 2.  So now my program always picks 5, 6, 2 when it auto-boots.  Is there something simple here that I'm just missing about LOAD programs?  Thanks

Try RXB as it returns different number then XB does and the pattern of results will be similar but not the same as TI Basic.

The added bonus is you can run your LOAD program and get better results.

RXB has the same RANDOM NUMBER GENERATOR AS TI BASIC, but does not return the same numbers as TI BASIC.

 

A pseudo-random number (PRN) generator is usually implemented to generate the same sequence of numbers every time it is started with the same seed. This is true of both TI Basic and TI Extended Basic (XB). Though they have different seeds, those seeds are set to the same number every time a program is run.

 

The seed for TI Basic is at >83C0 and is set to >3567 each time TI Basic runs a program. RANDOMIZE grabs the VDP interrupt timer byte at >8379 and jams it into the low byte of >83C0.

 

The seed for XB is a floating point number stored as two halves at VRAM >03A0 and >03A5 and is set at 335212624223 every time XB runs a program. This number, rather than the one at >83C0, is used by RND, which updates >03A0 and >03A5 each time it is called. RANDOMIZE, on the other hand, does use >83C0 to change the XB seed by calling the GPL RAND function four times. The only thing that can be called random about XB’s RANDOMIZE is the initial value at >83C0, which is always different when an XB program runs, except when the program named LOAD is autorun. This guarantees that the first time RANDOMIZE runs, the value at >83C0 is unpredictable. Each time RANDOMIZE runs after that, >83C0 gets the next value in a repeatable sequence (from the same starting value), much like TI Basic’s RND. This does not really matter that much except when LOAD autoloads and runs. Then, and only then, does XB jam >3567 into >83C0, guaranteeing that the PRN sequence is the same every time the program autoruns!

 

...lee

  • Like 2

Thanks for all the info.  Good to know it's not some random bug (I didn't think so since it happens on both my real machine and in Classic 99).  I thought there might be some common workaround I wasn't aware of but it seems based on the above that there is just no way around this when executing automatically from a LOAD file.  Well maybe with RXB, I'll have to give that a try in the emulator but unfortunately I don't have that physically for my real TI.  And to answer your question Tursi, yes I was trying to re-execute quickly from the main screen, but no it doesn't matter how long I hang on the main screen, it still gives the same sequence when the program is auto-loaded (at least on the real machine, haven't yet tried in Classic99).

 

I guess that means any games I've been working on I had better not plan on making auto-loading as they all use random elements in some form or another.

 

Also this begs another deeper question in my case specifically--I have a NanoPEB with a bunch of game compilations on it.  Since disk images can be much larger than 5 1/4" disks, I put several games on each disk image to conserve space on the flash card.  Then I made auto-load XB menus for each disk image so I could quickly load games without cataloging a disk to find an executable, especially considering all the files that would end up in these compilations.  So now I'm wondering if my auto-load in the beginning might kill a games' sense of randomness...  true XB games anyway--I realize that a lot of stuff isn't necessarily written in XB but can be converted to an XB executable--these games would presumably not be affected.  Not that I've ever noticed any non-random behavior before but it's food for thought anyway.

38 minutes ago, ruthven said:

I guess that means any games I've been working on I had better not plan on making auto-loading as they all use random elements in some form or another.

Your game must have a title page, doesn't it? Just call RND repeatedly while waiting for the user to press a key - that was my initial suggestion. It's much harder to predict how long the user will sit there. ;)

 

  • Like 5
9 hours ago, OLD CS1 said:

What effect on RANDOMIZE does running a second program from LOAD have?  Say, LOAD is a title screen or menu which then runs the real program.

You will get a similar number the best way to always get a better random number is use a seed

RANDOMIZE SEED so each seed can be different thus a different random number.

39 minutes ago, RXB said:

You will get a similar number the best way to always get a better random number is use a seed

RANDOMIZE SEED so each seed can be different thus a different random number.

And, from what I understand here, setting the seed in LOAD will not fix things, it has to be done in the actual program, correct?

2 hours ago, OLD CS1 said:

And, from what I understand here, setting the seed in LOAD will not fix things, it has to be done in the actual program, correct?

10 CALL KEY(5,K,S) :: RANDOMIZE INT(RND*100) :: IF S=0 THEN 10

 

As the key press time will be dependent on person it is unlikely you will ever get the same value each time.

17 hours ago, OLD CS1 said:

What effect on RANDOMIZE does running a second program from LOAD have?  Say, LOAD is a title screen or menu which then runs the real program.

 

It has the same unfortunate effect. Any chaining of programs started with an autoload of DSK1.LOAD will each start with >3567 at >83C0 and RANDOMIZE will always give the same next seed.

 

...lee

  • Like 1

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...