Page 1 of 2
Fatal Error Program
Posted: Tue Feb 16, 2016 10:15 am
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
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 10:58 am
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.
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 12:18 pm
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
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 12:40 pm
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!
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 12:45 pm
by tofro
The interpreter does check SELect structuring statically: If you just put a line like
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
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 1:00 pm
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
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 1:08 pm
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.
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 2:07 pm
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.
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 8:50 pm
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
Re: Fatal Error Program
Posted: Tue Feb 16, 2016 9:44 pm
by vanpeebles
Are you guys going to reinvent the market for lottery, pools and race horse predictors?
