IPC Command RAND_CMD ($14)

Anything QL Software or Programming Related.
Post Reply
spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

IPC Command RAND_CMD ($14)

Post 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


User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: IPC Command RAND_CMD ($14)

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


spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Re: IPC Command RAND_CMD ($14)

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


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: IPC Command RAND_CMD ($14)

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


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: IPC Command RAND_CMD ($14)

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


User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: IPC Command RAND_CMD ($14)

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


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: IPC Command RAND_CMD ($14)

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


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply