{"id":4783,"date":"2015-06-17T21:24:55","date_gmt":"2015-06-17T19:24:55","guid":{"rendered":"http:\/\/www.valcon.it\/pp\/?p=4783"},"modified":"2025-08-26T18:07:03","modified_gmt":"2025-08-26T16:07:03","slug":"prng-funzioni","status":"publish","type":"post","link":"https:\/\/www.valcon.it\/pp\/prng-funzioni\/","title":{"rendered":"Numeri pseudocasuali &#8211; Funzioni"},"content":{"rendered":"\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.valcon.it\/pp\/calcolo-prob-stat\/\">Calcolo d. prob. e stat.<\/a><\/div>\n<\/div>\n\n\n\n<p>Gli ambienti di sviluppo rendono disponibili una o pi\u00f9 funzioni per la generazione di <em>numeri casuali<\/em><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><\/th><th><\/th><th>Reali<\/th><th>Interi<\/th><\/tr><\/thead><tbody><tr><td><strong>BASIC<\/strong><\/td><td><strong><tt>RND()<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>Calc \/ Excel<\/strong><\/td><td><strong><tt>CASUALE()<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td><\/td><\/tr><tr><td><\/td><td><strong><tt>CASUALE.TRA(INF; SUP)<\/tt><\/strong><\/td><td><\/td><td>[INF, SUP]<\/td><\/tr><tr><td><strong>GeoGebra<\/strong><\/td><td><strong><tt>random()<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td><\/td><\/tr><tr><td><strong>Java \/ Javascript<\/strong><\/td><td><strong><tt>Math.random()<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>Pascal<\/strong><\/td><td><strong><tt>Random<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td><\/td><\/tr><tr><td><\/td><td><strong><tt>Random(SUP)<\/tt><\/strong><\/td><td><\/td><td>[0, SUP-1]<\/td><\/tr><tr><td><strong>Python<\/strong><\/td><td><strong><tt>random.random()<\/tt><\/strong><\/td><td>[0.0&#8230;1.0)<\/td><td><\/td><\/tr><tr><td><\/td><td><strong><tt>random.uniform(INF,SUP)<\/tt><\/strong><\/td><td>[INF, SUP)<\/td><td><\/td><\/tr><tr><td><\/td><td><strong><tt>random.randint(INF,SUP)<\/tt><\/strong><\/td><td><\/td><td>[INF, SUP]<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Numeri in un intervallo<\/h2>\n\n\n\n<p>A partire dalla funzione di base si possono ottenere numeri distribuiti uniformemente in un intervallo a piacere.<\/p>\n\n\n\n<p>Numeri reali (sostituisci CASUALE() con la funzione specifica del linguaggio)<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><\/th><th>[0..1)<\/th><th>[0..SUP)<\/th><th>[0..SUP-INF)<\/th><th>[INF..SUP)<\/th><\/tr><\/thead><tbody><tr><td rowspan=\"2\"><strong>Calc \/ Excel<\/strong><\/td><td>CASUALE()<\/td><td>SUP*CASUALE()<\/td><td>(SUP-INF)*CASUALE()<\/td><td>(SUP-INF)*CASUALE()+INF<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Numeri interi<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><\/th><th>[0, SUP-1]<\/th><th>[1, SUP]<\/th><th>[INF, SUP]<\/th><\/tr><\/thead><tbody><tr><td><strong>Java<\/strong><\/td><td><tt>(int)(SUP*<strong>Math.random()<\/strong>)<br><\/tt><\/td><td><tt>(int)(SUP*<strong>Math.random()<\/strong>+1)<\/tt><\/td><td><tt>(int)((SUP-INF+1)<\/tt><br><tt>*<strong>Math.random()<\/strong>+INF)<\/tt><\/td><\/tr><tr><td><strong>Javascript<\/strong><\/td><td><tt>Math.floor(SUP*<strong>Math.random()<\/strong>)<br><\/tt><\/td><td><tt><tt>Math.floor<\/tt>(SUP*<strong>Math.random()<\/strong>+1)<\/tt><\/td><td><tt><tt>Math.floor<\/tt>((SUP-INF+1)<\/tt><br><tt>*<strong>Math.random()<\/strong>+INF)<\/tt><\/td><\/tr><tr><td><strong>Pascal<\/strong><\/td><td><tt>Random(SUP)<\/tt><\/td><td><tt>Random(SUP)+1<\/tt><\/td><td><tt>Random(SUP-INF+1)+INF<\/tt><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><script>function genera() { var m =parseInt(document.form_random.minimo.value); var M =parseInt(document.form_random.massimo.value); var int1=M-m; var int2=M-m+1; var x =Math.random(); var x2 =M*x; var x3 =Math.floor(x2); var x4 =M*x+1; var x5 =Math.floor(x4); var x6 =int1*x+m; var x7 =Math.floor(x6); var x8 =int2*x+m; var x9 =Math.floor(x8); document.form_random.out_1.value=x; document.form_random.out_2.value=x2; document.form_random.out_3.value=x3;  document.form_random.out_4.value=x4; document.form_random.out_5.value=x5; document.form_random.out_6.value=x6; document.form_random.out_7.value=x7; document.form_random.out_8.value=x8; document.form_random.out_9.value=x9; }<\/script><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prova!<\/h2>\n\n\n<form name=\"form_random\">\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><\/th><th>Reali<\/th><th>Interi<\/th><\/tr><\/thead><tbody><tr><td><code>Math.random()<\/code><\/td><td><input name=\"out_1\" readonly=\"readonly\" type=\"text\"><\/td><td>Math.floor(&#8230;)<\/td><\/tr><tr><td><code>SUP*Math.random()<\/code><\/td><td><input name=\"out_2\" readonly=\"readonly\" type=\"text\"><\/td><td><input name=\"out_3\" readonly=\"readonly\" type=\"text\"><\/td><\/tr><tr><td><code>SUP*Math.random()+1<\/code><\/td><td><input name=\"out_4\" readonly=\"readonly\" type=\"text\"><\/td><td><input name=\"out_5\" readonly=\"readonly\" type=\"text\"><\/td><\/tr><tr><td><code>(SUP-INF)*Math.random()+INF<\/code><\/td><td><input name=\"out_6\" readonly=\"readonly\" type=\"text\"><\/td><td><input name=\"out_7\" readonly=\"readonly\" type=\"text\"><\/td><\/tr><tr><td><code>(SUP-INF+1)*Math.random()+INF<\/code><\/td><td><input name=\"out_8\" readonly=\"readonly\" type=\"text\"><\/td><td><input name=\"out_9\" readonly=\"readonly\" type=\"text\"><\/td><\/tr><tr><td><\/td><td><input name=\"minimo\" size=\"10\" type=\"text\" value=\"1\"> INF<\/td><td><\/td><\/tr><tr><td><\/td><td><input name=\"massimo\" size=\"10\" type=\"text\" value=\"10\"> SUP<\/td><td><\/td><\/tr><tr><td><\/td><td><input type=\"button\" value=\"Genera!\" onclick=\"genera()\"><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<\/form>","protected":false},"excerpt":{"rendered":"<p>Gli ambienti di sviluppo rendono disponibili una o pi\u00f9 funzioni per la generazione di numeri casuali Reali Interi BASIC RND() [0.0&#8230;1.0) &nbsp; Calc \/ Excel CASUALE() [0.0&#8230;1.0) CASUALE.TRA(INF; SUP) [INF, SUP] GeoGebra random() [0.0&#8230;1.0) Java \/ Javascript Math.random() [0.0&#8230;1.0) &nbsp; Pascal Random [0.0&#8230;1.0) Random(SUP) [0, SUP-1] Python random.random() [0.0&#8230;1.0) random.uniform(INF,SUP) [INF, SUP) random.randint(INF,SUP) [INF, SUP] &#8230; <a title=\"Numeri pseudocasuali &#8211; Funzioni\" class=\"read-more\" href=\"https:\/\/www.valcon.it\/pp\/prng-funzioni\/\" aria-label=\"Per saperne di pi\u00f9 su Numeri pseudocasuali &#8211; Funzioni\">Leggi tutto<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,83],"tags":[],"class_list":["post-4783","post","type-post","status-publish","format-standard","hentry","category-probabilita-e-statistica","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/4783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/comments?post=4783"}],"version-history":[{"count":22,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/4783\/revisions"}],"predecessor-version":[{"id":58631,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/4783\/revisions\/58631"}],"wp:attachment":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/media?parent=4783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/categories?post=4783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/tags?post=4783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}