4 ms·
I have no QBasic at hand right now, but the random generator was realy bad. I started programming with QBasic in my teens and so I just would do so fun with the
by _trampeltier 6y ago
I have no QBasic at hand right now, but the random generator was realy bad. I started programming with QBasic in my teens and so I just would do so fun with the random generator.
When you set the SCREEN 16 (640x480 16colors) use the first random number for the X position, the second for Y, the third random number just generate, but don't use and random number 4 is for the color 0-16. Then just draw a point and loop. The result is a picture with just diagonal lines. The line borders are a bit blurry, but else really straight, no curves or other artefacts.
The third random numer was for circle size, as I said, I learnd programming with it.
- lopmotr 6y agoIncredible. I did the same thing decades ago and got the same diagonal lines. I couldn't work out what was going wrong.
- _trampeltier 6y agoI knew already computer random is not really random, but expected a bit more randomness than just diagonal lines :-)
- acqq 6y agoI remember the Spectrum Basic Programming (the book included when buying ZX Spectrum, famous UK home computer) by Steven Vickers, 1982, 38 years ago: 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 https://ibb.co/kB2qS2L 3) Is the suggested proof online now somewhere?
- acqq 6y agoAnd the author of that book is a mathematician: https://en.wikipedia.org/wiki/Steve_Vickers_(computer_scientist) https://en.wikipedia.org/wiki/Steve_Vickers_(computer_scient... https://www.cs.bham.ac.uk/~sjv/ 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."
- 7thaccount 6y agoFYI, the ZX Spectrum Next is still available for pre-order until the end of the year. The original run was a successful Kickstarter campaign, so I had enough confidence to pony up $325 pounds for one. It is beautiful and has a lot of modern conveniences like USB/HDMI/VGA/WiFi...etc. People still make new games too. It's a cool scene.
- acqq 6y agoThank you and please note who submitted this 4 days ago: https://news.ycombinator.com/item?id=25081121 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.
- 7thaccount 6y agoI figured it might have been submitted, but didn't recall seeing it. Thanks for linking. I missed out on this entire era, so I've been excited about the potential to experience it with some modern advancements :).
- petercooper 6y agoI could only dig up QBasic 1.1 and maybe it was fixed there as I'm unable to reproduce the problem. I do recall discovering similar things myself at the time though! :-) This is my code and the end result. Let me know if I should be making some tweaks: https://imgur.com/a/98x0soS https://imgur.com/a/98x0soS
- TonyTrapp 6y agoLet it run for a little bit longer (and increase DOSBox cycles to speed it up). The code is correct.
- petercooper 6y agoThe caffeine hadn't kicked in enough earlier and I forgot you could just speed it up(!) .. having done that, I am now seeing what was speculated: https://imgur.com/a/hgWEA0H https://imgur.com/a/hgWEA0H 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/ https://www.qbasic.net/en/top-ten-downloads/
- _trampeltier 6y agoSorry, number 3 was the color and number 4 was spare. https://imgur.com/a/SSfaewf https://imgur.com/a/SSfaewf
- petercooper 6y agoAha! Certainly more striking :-) Leaving mine running did result in a pattern (though weaker) nonetheless though: https://imgur.com/a/hgWEA0H https://imgur.com/a/hgWEA0H