{"id":235,"date":"2016-06-15T11:37:27","date_gmt":"2016-06-15T09:37:27","guid":{"rendered":"http:\/\/www.hunggartorino.it\/ql\/?p=235"},"modified":"2016-05-13T14:55:32","modified_gmt":"2016-05-13T12:55:32","slug":"numeri-casuali-e-ql","status":"publish","type":"post","link":"https:\/\/www.hunggartorino.it\/ql\/numeri-casuali-e-ql\/","title":{"rendered":"QL and random numbers"},"content":{"rendered":"<p>Recently in the Italian mailing list we&#8217;ve discussed about the real randomness of the &#8220;random&#8221; numbers created by QL through its command RND.<\/p>\n<p><span id=\"result_box\" class=\"\" lang=\"en\"><span class=\"hps\">Unlike<\/span> <span class=\"hps\">on the<\/span> <span class=\"hps\">ZX<\/span> <span class=\"hps\">Spectrum<\/span>, whose <span class=\"hps\">corresponding<\/span> <span class=\"hps\">function<\/span> <span class=\"hps\">will never generate<\/span> <span class=\"hps\">certain values<\/span>, on <span class=\"hps\">QL<\/span> <span class=\"hps\">the numbers seem<\/span> <span class=\"hps\">really<\/span> <span class=\"hps\">random<\/span>.<\/span><\/p>\n<p>Let&#8217;s try with a simple three lines program:<\/p>\n<blockquote><p>REPeat CR_POINTS<br \/>\nPOINT RND(255),RND(255)<br \/>\nEND REPeat<\/p><\/blockquote>\n<p>This program is supposed to print random points, therefore the displayed rectangle should be completely filled after some time.<\/p>\n<p><a href=\"http:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/Immagine.jpg\" rel=\"attachment wp-att-237\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-237\" src=\"http:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/Immagine.jpg\" alt=\"Immagine\" width=\"253\" height=\"232\" \/><\/a><\/p>\n<p><span id=\"result_box\" class=\"\" lang=\"en\"><span class=\"hps\">From<\/span> <span class=\"hps\">first glance<\/span> <span class=\"hps\">it appears that<\/span> <span class=\"hps\">some areas<\/span> <span class=\"hps\">are<\/span> <span class=\"hps\">titally improbable<\/span> <span class=\"hps\">because<\/span> <span class=\"hps\">there are<\/span> <span class=\"hps\">&#8220;holes<\/span>&#8221; <span class=\"hps\">and rows<\/span> <span class=\"hps\">where<\/span> <span class=\"hps\">QL<\/span> <span class=\"hps\">will never<\/span> <span class=\"hps\">print points<\/span>. <span class=\"hps\">In<\/span> <span class=\"hps\">fact, the<\/span> <span class=\"hps\">proposed program<\/span> <span class=\"hps\">is not complete<\/span> <span class=\"hps\">because<\/span><span class=\"hps\"> there is not only<\/span> <span class=\"hps\">POINT<\/span>, but also<span class=\"hps\"> other<\/span> <span class=\"hps\">commands and<\/span> <span class=\"hps\">methods to draw<\/span> <span class=\"hps\">points<\/span> <span class=\"hps\">on the<\/span> <span class=\"hps\">QL<\/span>: <span class=\"hps\">PLOT<\/span> <span class=\"hps atn\">(<\/span><span class=\"\">to be loaded<\/span>,<span class=\"hps\"> non-native<\/span> in <span class=\"hps\">Qdos<\/span>) <span class=\"hps\">and<\/span> <span class=\"hps\">BLOCK<\/span>. <span class=\"hps\">A<\/span> <span class=\"hps\">mailing list<\/span> <span class=\"hps atn\">user (<\/span><span class=\"hps atn\">&#8220;<\/span><span class=\"\">CRX<\/span><span class=\"\">&#8220;<\/span>)<span class=\"hps\"> analyzed this issue<\/span> <span class=\"hps\">and<\/span> <span class=\"hps\">made some tests<\/span> <span class=\"hps\">with the three<\/span> keywords adding <span class=\"hps\">color<\/span>. <span class=\"hps\">We get<\/span> <span class=\"hps\">different results<\/span>.<\/span><\/p>\n<pre>100 REMark *** RANDOMNESS ***\r\n110 REMark ~~~~~~~~~~~~~~~~~~\r\n120 MODE 8: PAPER 0\r\n130 WINDOW 512,256,0,0: CLS\r\n140 INK 5: CSIZE 0,1: CURSOR 77,130: PRINT \"Point       Block      Plot\"\r\n150 :\r\n160 FOR points=1 TO 3000\r\n170   POINT RND(22 TO 40),RND(60 TO 80)\r\n180   INK RND(1 TO 7)\r\n190 END FOR points\r\n200 :\r\n210 FOR blocks=1 TO 5000\r\n220   BLOCK 2,1,RND(218 TO 280),RND(50 TO 100),RND(1 TO 7)\r\n230 END FOR blocks\r\n240 :\r\n250 REMark ** Requires PLOT &amp; DRAW **\r\n260 REMark ~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n270 :\r\n280 FOR plots=1 TO 5000\r\n290   PLOT RND(350 TO 410),RND(50 TO 100)\r\n300   INK RND(1 TO 7)\r\n310 END FOR plots<\/pre>\n<p><a href=\"http:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi.jpg\" rel=\"attachment wp-att-238\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-238 aligncenter\" src=\"http:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi-199x300.jpg\" alt=\"4casi\" width=\"199\" height=\"300\" srcset=\"https:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi-199x300.jpg 199w, https:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi-768x1155.jpg 768w, https:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi-681x1024.jpg 681w, https:\/\/www.hunggartorino.it\/ql\/wp-content\/uploads\/2016\/03\/4casi.jpg 1200w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/a><\/p>\n<p><span id=\"result_box\" class=\"\" lang=\"en\"><span class=\"hps\">In all<\/span> <span class=\"hps\">cases<\/span> <span class=\"hps\">POINT<\/span> <span class=\"hps\">never<\/span> <span class=\"hps\">fills<\/span> <span class=\"hps\">the rectangle<\/span> <span class=\"hps\">but<\/span> <span class=\"hps\">puts<\/span> <span class=\"hps\">the pixels<\/span> <span class=\"hps\">following<\/span> <span class=\"hps\">a sort of grid<\/span>, <span class=\"hps\">both<\/span> <span class=\"hps\">on<\/span> <span class=\"hps\">real<\/span> <span class=\"hps\">QL<\/span> <span class=\"hps\">and<\/span> <span class=\"hps\">on<\/span> <span class=\"hps\">emulator<\/span>. <span class=\"hps\">With\u00a0<\/span> <span class=\"hps\">recent<\/span> <span class=\"hps\">Minerva<\/span> ROM, <span class=\"hps\">colors appear<\/span> <span class=\"hps\">anything but random<\/span>. <span class=\"hps\">With<\/span> older <span class=\"hps\">Minerva<\/span> <span class=\"hps\">and<\/span> <span class=\"hps\">JS<\/span> ROMs\u00a0 <span class=\"hps\">instead,<\/span> <span class=\"hps\">everything seems<\/span> <span class=\"hps\">more random<\/span><span class=\"hps\">&#8230;<\/span> <span class=\"hps\">but<\/span> <span class=\"hps\">observing carefully<\/span> <span class=\"hps\">we realize<\/span> <span class=\"hps\">that the pixels<\/span> <span class=\"hps\">are arranged<\/span> <span class=\"hps\">in exactly the<\/span> <span class=\"hps\">same scheme<\/span> <span class=\"hps\">and with the same<\/span> <span class=\"hps\">colors.<\/span> <span class=\"hps\">Since the<\/span> <span class=\"hps\">internal clock<\/span> of basic <span class=\"hps\">QL<\/span> <span class=\"hps\">has no<\/span> <span class=\"hps\">backup battery,<\/span> <span class=\"hps\">it<\/span> <span class=\"hps\">resets<\/span> <span class=\"hps\">every time you turn on the computer<\/span>; <span class=\"hps\">therefore<\/span> <span class=\"hps\">the <\/span><span class=\"hps\">he RND function<\/span>, <span class=\"hps\">which<\/span> <span class=\"hps\">is given by<\/span> <span class=\"hps\">a count<\/span> <span class=\"hps\">in fractions<\/span> <span class=\"hps\">of a second<\/span> starting <span class=\"hps\">from<\/span> <span class=\"hps\">the<\/span> <span class=\"hps\">QL<\/span> <span class=\"hps\">power on<\/span><span class=\"\">,<\/span> <span class=\"hps\">can be<\/span> <span class=\"hps\">modified<\/span> <span class=\"hps\">with the<\/span> <span class=\"hps\">RANDOMISE<\/span> <span class=\"hps\">statement<\/span>.<\/span><\/p>\n<p>For example, with the command:<br \/>\nRANDOMISE DATE<br \/>\nwe get immediatly more random-looking rectangles, avoiding the &#8220;rainbow effect&#8221;.<\/p>\n<p><span id=\"result_box\" class=\"\" lang=\"en\"><span class=\"hps\">As for<\/span> <span class=\"hps\">the holes that<\/span> <span class=\"hps\">visible<\/span> <span class=\"hps\">with<\/span><span class=\"hps\"> POINT<\/span> <span class=\"hps\">compared<\/span> <span class=\"hps\">to other<\/span> <span class=\"hps\">commands<\/span><span class=\"\">,<\/span> <span class=\"hps\">actually<\/span> <span class=\"hps\">it is due<\/span> <span class=\"hps\">to the fact that<\/span> <span class=\"hps\">POINT<\/span><span class=\"\">, unlike<\/span> <span class=\"hps\">BLOCK<\/span> <span class=\"hps\">and<\/span> <span class=\"hps\">PLOT<\/span>, uses <span class=\"hps\">the<\/span> <span class=\"hps\">graphic coordinate system and<\/span> <span class=\"hps\">not<\/span> the <span class=\"hps\">pixels.<\/span> <span class=\"hps\">Therefore<\/span> <span class=\"hps\">it requires<\/span> <span class=\"hps\">coordinates with<\/span> <span class=\"hps\">fractional<\/span> <span class=\"hps\">values<\/span> also <span class=\"hps atn\">(<\/span><span class=\"\">POINT<\/span> <span class=\"hps\">3.5,8.5<\/span>) in order <span class=\"hps\">to<\/span> <span class=\"hps\">switch on all the<\/span> <span class=\"hps\">pixels<\/span>, while <span class=\"hps\">RND<\/span> <span class=\"hps\">provides only<\/span> <span class=\"hps\">integers<\/span><span class=\"\">.<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #b3b3b3;\"><em>Photo: <a class=\"gallery_link\" style=\"color: #b3b3b3;\" title=\"Dirty numbers\" href=\"https:\/\/www.google.it\/url?sa=i&amp;rct=j&amp;q=&amp;esrc=s&amp;source=images&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwiA-9Xv7rDLAhUDQBQKHRX-BvIQjhwIBQ&amp;url=https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fsidelong%2F3466699346&amp;bvm=bv.116274245,d.d24&amp;psig=AFQjCNFjX79CQ8YbovTx3QBoh-GTyghQFw&amp;ust=1457518755756994\">red numbers <\/a>\u00a0 by DaveBleasdale \/\u00a0 <a id=\"yui_3_16_0_1_1457430934257_1933\" class=\"photo-license-url\" style=\"color: #b3b3b3;\" href=\"https:\/\/creativecommons.org\/licenses\/by\/2.0\/\" target=\"_newtab\" rel=\"license cc:license\" data-rapid_p=\"34\"><span id=\"yui_3_16_0_1_1457430934257_1932\">CC BY\u00a0 <\/span><\/a><\/em><em>\/ Blurred from original<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"Recently in the Italian mailing list we&#8217;ve discussed about the real randomness of the &#8220;random&#8221; numbers created by QL through its command RND. \n<a class=\"moretag\" href=\"https:\/\/www.hunggartorino.it\/ql\/numeri-casuali-e-ql\/\"> [..more...]<\/a>","protected":false},"author":3,"featured_media":318,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[51],"class_list":["post-235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-senza-categoria","tag-programmazione-en"],"_links":{"self":[{"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":8,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":370,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/235\/revisions\/370"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/media\/318"}],"wp:attachment":[{"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}