Fatal Error Program

Anything QL Software or Programming Related.
User avatar
dilwyn
Mr QL
Posts: 3134
Joined: Wed Dec 01, 2010 10:39 pm

Fatal Error Program

Post by dilwyn »

OK, guys, here's one to keep you amused. Not had my morning coffee yet so I haven't got my thinking cap on...
Someone sent me this little program which shows a side effect of a programming mistake.
It stops with the error "At line 130:1 fatal error in SBASIC interpreter" on QPC2 4.02

The reason it doesn't run is obviously the GOTO statement should got to line 110, not 130, but interesting that this causes a fatal error!

Code: Select all

100 CLS
110 r=RND(1 TO 3)
120 SELect ON r
130   =1 : PRINT'-';
140   =2 : PRINT'|';
150   =3 : PRINT'+';
160 END SELect
170 PAUSE 2
180 GO TO 130


Derek_Stewart
Font of All Knowledge
Posts: 4798
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Fatal Error Program

Post by Derek_Stewart »

Hi Dilwyn,

SMSQmulator gives the same error.

However Q-Emulator with Minerva v1.98 runs the programme.

But I would say, the GOTO should be repalce with a REPeat loop

Another case of bad programming... and not reading the manual correctly.


Regards, Derek
User avatar
pjw
QL Wafer Drive
Posts: 1630
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Fatal Error Program

Post by pjw »

Code: Select all

100 GO TO 120
110 SELect ON x
120 = 0: REMark Bang!
130 END SELect
Its SBASIC. However, the interpreter doesnt appear to be crashed. I guess its just lost for words that something this dumb could be asked of it - so my guess is that its merely a catch-all error message.

per


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
User avatar
dilwyn
Mr QL
Posts: 3134
Joined: Wed Dec 01, 2010 10:39 pm

Re: Fatal Error Program

Post by dilwyn »

That's what I thought - it seems there's no more to it than there is no error message to cope with a programming mistake like this.

The original question I was asked is possibly more interesting:

Code: Select all

"I am trying to write a program to illustrate the fact that the so-called random number generator is actually nothing more than a mathematical equation. I don't know the equation, but I think it can be demonstrated by writing a program which will produce repeating patterns by varying window sizes to allow the random number generator to drive a pattern generator. Do you know the equation? Or do you know of any programs which will do this?"
I don't know where to start trying to answer this one. At least I've never been asked this before, unlike some of the never ending same old common questions!


User avatar
tofro
Font of All Knowledge
Posts: 3148
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Fatal Error Program

Post by tofro »

The interpreter does check SELect structuring statically: If you just put a line like

Code: Select all

1 =0: STOP
into your program and run it (or use that line in direct mode), it does come back with the proper error message
Incorrectly structured SELect clause
Apparently, it doesn't do the same thing if you GO TO the middle of a SELect statement. But it really doesn't need to check for every piece of rubbish.....

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 3148
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Fatal Error Program

Post by tofro »

dilwyn wrote:That's what I thought - it seems there's no more to it than there is no error message to cope with a programming mistake like this.

The original question I was asked is possibly more interesting:

Code: Select all

"I am trying to write a program to illustrate the fact that the so-called random number generator is actually nothing more than a mathematical equation. I don't know the equation, but I think it can be demonstrated by writing a program which will produce repeating patterns by varying window sizes to allow the random number generator to drive a pattern generator. Do you know the equation? Or do you know of any programs which will do this?"
I don't know where to start trying to answer this one. At least I've never been asked this before, unlike some of the never ending same old common questions!
Dilwyn,

Like always, the code is the answer:

RND(t+1) = (RND(t) & $ffff0000) * $c12d0000 + (RND(t) & $0000ffff) * $712d + 1

Code: Select all

rnd
	move.l	sb_rand(a6),d0
	move.w	d0,d4
	swap	d0
	mulu	#$c12d,d0		   ; multiply up
	mulu	#$712d,d4
	swap	d0
	clr.w	d0
	add.l	d0,d4
	addq.l	#1,d4
	move.l	d4,sb_rand(a6)		 ; and save it
(from rnd_asm in SMSQ/E sources)

Whatever that knowledge would be good for.....

BTW the rest of the question with windows and patterns I really didn't manage to understand.

I remember writing an article for the Toady once that was on RND and RANDOMIZE with some application of the characteristics of the RNG providing repeatable patterns. Maybe that person wants to look it up.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
dilwyn
Mr QL
Posts: 3134
Joined: Wed Dec 01, 2010 10:39 pm

Re: Fatal Error Program

Post by dilwyn »

Thanks Tobias. I'll pass on the info and hope that a nice program results!
I didn't understand the question either, but thought it was just my brain not working in this horrible cold high wind today.


Derek_Stewart
Font of All Knowledge
Posts: 4798
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Fatal Error Program

Post by Derek_Stewart »

Hi,

I think the reply Tobias gave does answer the question, but the problem is the seed that us put into the Random Number Generator is not really random is the Code provided.

The definition of Random (from Wikipedia):
Randomness is the lack of pattern or predictability in events. A random sequence of events, symbols or steps has no order and does not follow an intelligible pattern or combination. Individual random events are by definition unpredictable, but in many cases the frequency of different outcomes over a large number of events (or "trials") is predictable. For example, when throwing two dice, the outcome of any particular roll is unpredictable, but a sum of 7 will occur twice as often as 4. In this view, randomness is a measure of uncertainty of an outcome, rather than haphazardness, and applies to concepts of chance, probability, and information entropy.
The basic programme is problems in SMSQ/E as it is not structured correctly. I altered the programme in SMSQmulator to:

Code: Select all

100 CLS
110 REPeat loop
120   r=RND(1 to 3)
130   SELect ON r
140     =1: PRINT '-';
150     =2: PRINT '|';
160     =1: PRINT '-+;
170   END SELect
180   PAUSE 2
190 END REPeat loop
This does give a sort of random sequence in the range of 1 to 3. But I not sure it proves the Mathematical formula required.


Regards, Derek
User avatar
1024MAK
Super Gold Card
Posts: 593
Joined: Sun Dec 11, 2011 1:16 am
Location: Looking forward to summer in Somerset, UK...

Re: Fatal Error Program

Post by 1024MAK »

Um, to demonstrate that it is a pseudo random number generator, surely all you need to do is seed with a known number. Draw a graph on the screen using the resulting "random" number sequence. Stop, ask the user to press a key. Then clear the screen, seeding the same number and repeating the drawing of the graph. Then print out the code to show how it works...

Oh, and there are three forms of random number generators that I know of:-
  • Generated by picking results from the ROM
  • Purely mathematical
  • Special hardware (typically a fast and a slow astable multivibrator)
Mark
Last edited by 1024MAK on Tue Feb 16, 2016 10:05 pm, edited 1 time in total.


:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer in Somerset later in the year :)

QL, Falcon, Atari 520STFM, Atari 1040STE, more PC's than I care to count and an assortment of 8 bit micros (Sinclair and Acorn)(nearly forgot the Psion's)
User avatar
vanpeebles
Commissario Pebbli
Posts: 2854
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Fatal Error Program

Post by vanpeebles »

Are you guys going to reinvent the market for lottery, pools and race horse predictors? :lol:


Post Reply