{"id":5232,"date":"2014-08-21T18:19:40","date_gmt":"2014-08-21T18:19:40","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=5232"},"modified":"2014-08-21T18:19:40","modified_gmt":"2014-08-21T18:19:40","slug":"perl-programming-random-numbers","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-programming-random-numbers\/","title":{"rendered":"Perl programming:  random numbers"},"content":{"rendered":"<h1>Tutoring math, you realize that some of your students will move on to computer science at university.\u00a0 The tutor brings up a time-honoured favourite among comp-sci people:\u00a0 random number generation.<\/h1>\n<p>Every computer programming language I know of has a random number generator.\u00a0 The one I know in Perl is rand().\u00a0 Common among such functions, it gives a random number between 0 and 1:\u00a0 a decimal to 10 or so places.\u00a0 If you want a random whole number, you can\u00a0 multiply the output of rand() by 10, 100, 1000, or some other power of 10, then truncate it.\u00a0 The following little program serves an example:<\/p>\n<p>&nbsp;<br \/>\n<span style=\"font-family:monospace;color:brown\">#!\/usr\/bin\/perl<\/p>\n<p>$num0=rand();<\/p>\n<p>$num1=1000*$num0;<\/p>\n<p>$num2=int($num1);<\/p>\n<p>print &#8220;\\n\\nYour random number between 0 and 1000 is $num2\\n\\n&#8221;;<\/span><\/p>\n<p>How are random numbers accomplished?  There are several ways a computer might do so.  A deeper question is, &#8220;How can a computer generate a truly random number, when a computer calculates numbers rather than creates them?&#8221;  The answer lies in the compromise of accepting <em>unpredictable<\/em> as random.<\/p>\n<p>For more about this wonderful topic, please return soon.<\/p>\n<p><em>Source:<\/em> <a href=\"http:\/\/perlmeme.org\/howtos\/perlfunc\/rand_function.html\">perlmeme.org<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutoring math, you realize that some of your students will move on to computer science at university.\u00a0 The tutor brings up a time-honoured favourite among comp-sci people:\u00a0 random number generation. Every computer programming language I know of has a random &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-programming-random-numbers\/\"> <span class=\"screen-reader-text\">Perl programming:  random numbers<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[173,202,203],"class_list":["post-5232","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-perl-programming","tag-perl-random-number-generator","tag-rand"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=5232"}],"version-history":[{"count":21,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5232\/revisions"}],"predecessor-version":[{"id":5253,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5232\/revisions\/5253"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=5232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=5232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=5232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}