ENTROPY_GET

All aspects of programming on the Commander X16.
Post Reply
flimbo72
Posts: 3
Joined: Fri Jan 27, 2023 5:38 pm

ENTROPY_GET

Post by flimbo72 »

Hello everybody.

I'm currently using Kernal's ENTROPY_GET routine to shuffle a 5 elements array, but I get some quirks:

- a certain sequence shows up way too often
- occasionally a sequence comes up twice in a row

Upon extensive checking, I can safely claim that my shuffle algorithm is working properly, so I'm now questioning if ENTROPY_GET is a reliable random number generator.
Did any of you have a chance to deal with such routine? What do you think about it?

Thanks,
Giacomo
mortarm
Posts: 319
Joined: Tue May 16, 2023 6:21 pm

Re: ENTROPY_GET

Post by mortarm »

JAT, is there a way to initialize the seed before calling the routine, like you can in BASIC?
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: ENTROPY_GET

Post by desertfish »

I don't think there's a way to "seed" this, actually, I would argue the result of this call is meant to be a seed in its own.
The docs say:
This routine returns 24 somewhat random bits in registers .A, .X, and .Y. In order to get higher-quality random numbers, this data should be fed into a pseudo-random number generator.
So it's probably best to do that, and not continuously call this routine to get random numbers from.
Here's a pretty good prng https://codebase64.org/doku.php?id=base ... r_8_16_bit
Post Reply