2

Is there any way on the TI-84 calculators to create a "true" random number generator? I know the one built into the calculator is a pseudo-random number generator but is it at all possible to create a true RNG so that no matter what the user wants to seed the built in RNG with the result will always be random and not predictable even if they reseed it with the same seed after getting a set of numbers? My initial thought was to use the RNG in a For loop like this to randomize the seed but it occurred to me that by seeding the initial RNG it's still predictable. Here is the code I was using:

For(I,1,int(rand*100),1)
int(rand*100)→rand
End

But as I stated that didn't work.

Peter O.
  • 32,158
  • 14
  • 82
  • 96

3 Answers3

3

If you want to know this for security purposes (meaning secure from the user), consider that a TI-BASIC program is both inspectable and editable. Also when "protected" (which hides the program from the EDIT menu), which is as easy to undo as it is to "protect" the program in the first place.

The low bits of the R register are often considered "random enough", of course they are not really random, but under normal circumstances they are difficult to predict as any instruction the CPU executes also increments R by some amount, and on a macroscopic scale it is hard to predict what exactly the CPU will execute. Essentially it's like a clock but it changes more quickly and is more difficult to predict.

You could get the contents of R in a form usable from BASIC like this (you can AsmComp( it to save space)

:AsmPrgmED5FE63FEF8C47EFBF4AC9

Which corresponds to this snippet:

ld a, r
and $3F
bcall(_SETXXOP1)
bcall(_StoAns)
ret

As you can see, the result will be in Ans.

As long as a user runs the program without modifications, they will not be likely to guess the result (about a 1/64 chance), and even less likely to influence it in a directed way.

harold
  • 61,398
  • 6
  • 86
  • 164
  • My first question with this is since you mentioned Assembly, does that code work one the 84+CE? I know a lot of codes changed between 84 and CE and a bad assembly code results in a RAM clear. – Himitsu_no_Yami Sep 26 '19 at 15:54
  • @Himitsu_no_Yami the snippet assembly code would be the same, but it would translate to `AsmPrgmED5FE63FEF7747EFAA4AC9` – harold Sep 26 '19 at 17:12
2

You misunderstand what "true" vs. "pseudo" random number generators are. Any deterministic algorithm can only be a PRNG. If it doesn't produce the same results after being re-seeded with the same seed, then it's just a broken PRNG, because that's the very purpose of a seed.

A "true" RNG must have some physical hardware source of entropy as input. This can be something like a reverse-biased diode, a radiation source, microphone noise, etc. It must also know how much entropy is available in that source, and be careful to not produce too much output from the available input. Most modern microprocessors have special hardware and instructions for this. The Zilog Z80 does not. It might be possible to add hardware for this purpose.

Lee Daniel Crocker
  • 12,927
  • 3
  • 29
  • 55
  • So is there a way to instead prevent reseeding then? For my purposes I'd say that would be functionally equivalent. – Himitsu_no_Yami Sep 25 '19 at 21:54
  • I'm not even sure I understand the question. Do you not control the software running on the device? Who else would re-seed the RNG during your use? If you mean is there a way to create different seeds for different runs, probably. I don't know TI-BASIC, but there might be a way to access a clock, maybe, and seed from that? Or perhaps a way to store the last returned value and retrieve that for the next run? – Lee Daniel Crocker Sep 25 '19 at 22:00
  • That was more of a thing I was curious on if was doable but the clock idea is pretty good so thanks! – Himitsu_no_Yami Sep 25 '19 at 22:03
1

You can't within solely TI-BASIC. You need an external source like mic noice or radiation decay or something outside the calc. A computer simply cannot generate "true" randomness by itself. If you're using this for secruity purposes though, keep in mind TI-BASIC program are both inspectable AND editable. You can "protect" them but the only thing needed to crack the protection is to transfer the program to a computer and open it in TI's offical program editor. So yeah, don't use TI-BASIC for secruity.