Improving on QBasic's Random Number Generator
nullprogram.com
nullprogram.com
The quote from the Charpter 16: Colours
"Run this program:
10 POKE 22527+RND*704,RND*l27
20 GO TO 10
Never mind how this works; it is changing the colours of squares
on the television screen and the RNDs should ensure that this
happens randomly. The diagonal stripes that you eventually see are
a manifestation of the hidden pattern in RND - the pattern
that makes it pseudorandom instead of truly random." (1) (2)In another part of the manual it also explains the mathematical properties of the built-in random generator:
"(For mathematicians only.) Let p be a (large) prime, and let a be a primitive root modulo p. Then if bi is the residue of a’ modulo p (1 <= bi <= p-1), the sequence
(bi-1)/(p-1)
is a cyclical sequence of p-1 distinct numbers in the range 0 to 1 (excluding 1). By choosing a suitably, these can be made to look fairly random.
65537 is a Fermat prime, 2^16+1. Because the multiplicative group of non-zero residues modulo 65537 has a power of 2 as its order, a residue is a primitive root if and only if it is not a quadratic residue. Use Gauss’ law of quadratic reciprocity to show that 75 is a primitive root modulo 65537." (3)
---
1) It works by directly changing the "attributes" part of the memory which is directly mapped to the color of the 8x8 pixel part of the screen used for different characters (22 rows of 32 characters == 704), randomly selecting both the position on the screen and the value of the attribute, two calls per one loop pass. It's beautiful in how short the program is.
2) The appearance of "the diagonal stripes": https://ibb.co/kB2qS2L
3) Is the suggested proof online now somewhere?
https://en.wikipedia.org/wiki/Steve_Vickers_(computer_scient...
https://www.cs.bham.ac.uk/~sjv/
"My particular interest is in toposes as generalized spaces, with the connection between logic (specifically, geometric logic) and topology. These are areas of mathematics that have connections with computer science, although my work in them is often purely mathematical. Over 2017-18 I formalized an approach to topos theory using Joyal's Arithmetic Universes (AUs) as a substitute for Grothendieck toposes, potentially implementable on computers, and showed how to use it to obtain constructive, base-free results for toposes. My current work is on developing the techniques of this approach and exploring the extent to which it can capture Grothendieck's original applications of topos theory."
"I was a computer programmer for several years. I wrote the ROM and user manuals for two Sinclair computers, the ZX81 and the ZX Spectrum. Then with Richard Altwasser I founded Jupiter Cantab Ltd, which produced the Forth-based Jupiter Ace microcomputer."
https://news.ycombinator.com/item?id=25081121
However the topic in this thread is that the properties of the random number generators discussed in 2020 were a part of the user manual of the home computer in 1982, and I find that totally amazing and inspiring.
It is also explainable knowing who wrote both the ROM and the book, which I also mentioned.
This is my code and the end result. Let me know if I should be making some tweaks: https://imgur.com/a/98x0soS
BTW, for anyone else who wants in on this action. Download DOSBox then you can find various forms of BASIC at https://www.qbasic.net/en/top-ten-downloads/
Leaving mine running did result in a pattern (though weaker) nonetheless though: https://imgur.com/a/hgWEA0H
I actually used this technique to replace Nibbles’ busy-waiting delay loop with an invocation of interrupt 0x15 service 0x86.
- dim asm as string
- concatenate your assembly together
- DEF SEG = VARSEG(ASM)
- CALL ABSOLUTE(SADD(ASM))
No but BBC Basic did!
I have a feeling this was especially the case in the 90s, but there have been some great people sharing high-quality works in the early 2000s QBasic scene.
You're in for a shock, we're still in the "blind leading the blind" phase as GitHub stars and Twitter followers currently dictate who's a "leader" in the software engineering world. With the invention of social media and their likes, our work and "innovation" is driven by hype more than ever before.
> (note: the LCG constants listed here are wrong)
It's a buggy 24-bit multiply and the constants are accessed wrongly.
Look at the code https://www.qb64.org/forum/index.php?topic=1414.0:
The third MUL computes the same value as the first but it should be [RndA+2] * [RndVar] and not [RndA] * [RndVar] hence a=0fd43fdh instead of a=0343fdh. Also carries are not taken into account in the first two ADDs.
The addition of c is similarly buggy.
Turbo Basic predates QBasic (but was after and responded to QBasic's predecessor, QuickBasic.)
> It's totally source code compatible with QBasic.
I don't think that that is true of any version of Turbo/PowerBasic and any version Quick/QBasic.
Having to manually set the exit condition of a loop to avoid memory leaks