{"id":2764,"date":"2019-11-20T05:33:19","date_gmt":"2019-11-20T05:33:19","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=2764"},"modified":"2019-11-20T05:33:20","modified_gmt":"2019-11-20T05:33:20","slug":"an-experiment-in-randomness","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/an-experiment-in-randomness\/","title":{"rendered":"An Experiment in Randomness"},"content":{"rendered":"\n<p>You can print a random number between 1-10 with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo $((( RANDOM % 10 )+1))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Creating random numbers<\/h2>\n\n\n\n<p>If you change it so the output is between 0-9 you get decently even results.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat \/dev\/null > random.txt &amp;&amp; cat \/dev\/null > random2.txt &amp;&amp; for ((i=0; i&lt;=9999;i++)); do echo $((( RANDOM % 10 ))) >> random.txt ; done &amp;&amp; for ((i=0; i&lt;=9;i++)); do echo $(grep -c $i random.txt) $i; done  |  sort -n<\/pre>\n\n\n\n<p><em>Note that you can change the command to be between 1-10, but all the 1&#8217;s in 10 will get grepped and counted as 1&#8217;s.<\/em><\/p>\n\n\n\n<p>The above command should return something similar to the following.  Sorted by lowest occurrences first.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">943 5\n945 8\n985 7\n996 2\n997 6\n1005 3\n1012 9\n1016 4\n1033 0\n1068 1\nadmin@localhost:~$<\/pre>\n\n\n\n<p>We can plot them in LibreOffice Calc.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"813\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4-1024x813.png\" alt=\"\" class=\"wp-image-2808\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4-1024x813.png 1024w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4-300x238.png 300w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4-768x610.png 768w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4-378x300.png 378w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-4.png 1081w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Plot with GnuPlot<\/h2>\n\n\n\n<p>Gnuplot is another utility that you can use to plot numbers.  Example is below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/dev\/null > random.txt &amp;&amp; cat \/dev\/null > random2.txt &amp;&amp; for ((i=0; i&lt;=9999;i++)); do echo $((( RANDOM % 10 ))) >> random.txt ; done &amp;&amp; for ((i=0; i&lt;=9;i++)); do echo $i $(grep -c $i random.txt) ; done  |  sort -n | gnuplot -p -e 'plot \"\/dev\/stdin\"'<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"676\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-5.png\" alt=\"\" class=\"wp-image-2810\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-5.png 770w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-5-300x263.png 300w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-5-768x674.png 768w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2019\/11\/image-5-342x300.png 342w\" sizes=\"auto, (max-width: 770px) 100vw, 770px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>You can print a random number between 1-10 with the following command. echo $((( RANDOM % 10 )+1)) Creating random numbers If you change it so the output is between 0-9 you get decently even results. cat \/dev\/null > random.txt &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/an-experiment-in-randomness\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[809],"tags":[757,810,7,752],"class_list":["post-2764","post","type-post","status-publish","format-standard","hentry","category-random","tag-echo","tag-gnuplot","tag-linux-2","tag-random"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=2764"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2764\/revisions"}],"predecessor-version":[{"id":2811,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2764\/revisions\/2811"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=2764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=2764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=2764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}