Page 1 of 1

IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 9:12 pm
by spkr
Hi there guys,

Im looking to generate random numbers on demand, and I suppose the IPC Link is able to do this, by issuing the RAND_CMD (http://sinclairql.net/downloads/1984-00 ... d-SQPP.pdf, page 142); but I find no documentation as how to form the IPC command.

Is anyone able to point me into the right direction?

Regards,
Wietze

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 9:42 pm
by janbredenbeek
spkr wrote:Hi there guys,

Im looking to generate random numbers on demand, and I suppose the IPC Link is able to do this, by issuing the RAND_CMD (http://sinclairql.net/downloads/1984-00 ... d-SQPP.pdf, page 142); but I find no documentation as how to form the IPC command.
From Andrew Pennell's QDOS Companion:

"This command is $E 0 ? ? ? ? 2 which returns a pseudo-random number. It is best to use only the lowest four bits though, as the highest bits tend to be zero most of the time. This is not a very good way of generating random numbers, and it's better either to read the system variable SV.RAND, or to generate your own with the floating point maths routines."

Regards, Jan.

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 9:55 pm
by spkr
Thanks for the reply, yeah it seems that getting 4 bits of randomness is a bit meh. Thanks, Ill read the system variable once to use as a seed and implement some pseudorandom number generation based on that.

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 10:00 pm
by stevepoole
Hi,

Yes Jan, we can write our own 9-digit integer random number routines.

But the main problem is how to SEED the generator : Quite easy on a QL emulator, but very hard on a non-multitasking QL !
(I have used a few methods, but none are fully satisfying).

Randomness is a subject of continued research by specialists...

Steve.

PS: if you want BIG random integers, the easiest solution is to concatenate QL ones yourself.

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 10:04 pm
by XorA
stevepoole wrote: Randomness is a subject of continued research by specialists...
Not really, anything made in last decade has hardware randomness, PN junction noise and other such simple techniques.

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 10:19 pm
by janbredenbeek
I believe SV.RAND uses a better random generator algorithm on SMSQ/E than on QDOS/Minerva, which just increments it on every scheduler loop.

Re: IPC Command RAND_CMD ($14)

Posted: Wed May 26, 2021 11:19 pm
by NormanDunbar
I did some randomisation stuff in the somewhat irregular ePeriodical on assembly language, Issue 8. Available at https://github.com/NormanDunbar/QLAssem ... ag/Issue_8, it all kicks off on page 47.

If it's of any use? Basically it is pretty much a blatant rip off of the SMSQ code!

Cheers,
Norm.