{"id":8052,"date":"2018-02-15T10:30:44","date_gmt":"2018-02-15T10:30:44","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=8052"},"modified":"2022-01-05T11:14:34","modified_gmt":"2022-01-05T11:14:34","slug":"congruential-generation-of-pseudo-random-numbers-in-c","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/congruential-generation-of-pseudo-random-numbers-in-c\/","title":{"rendered":"Congruential Generation of Pseudo-Random Numbers in C++"},"content":{"rendered":"<h2>Congruential Method of Formation of Pseudo-Random Numbers<\/h2>\n<p>We need to program a generator of pseudo-random numbers using the congruential method of formation of pseudo-random numbers.<\/p>\n<p>Random numbers means the possible values xi of a continuous random variable X, distributed uniformly on the interval [0;1).<\/p>\n<p>The formula defining the congruential method of generating pseudo-random numbers is represented like this:<\/p>\n<p><!--more--><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/02\/Pseudo-Random-cpp.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8056 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/02\/Pseudo-Random-cpp.jpg\" alt=\"\" width=\"350\" height=\"212\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/02\/Pseudo-Random-cpp.jpg 350w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/02\/Pseudo-Random-cpp-300x182.jpg 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">where, a0, a1, . . . aj \u2014 multipliers<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00b5 \u2014 increment value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y1, y2, . . . yn \u2014 resulting random number<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x1, x2, . . . , xn \u2014 random numbers on the interval [0;1)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The program generates 15 random numbers, and for the result of the program see below. All the random numbers lie in the interval [0;1).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So considering the formula we should obtain such result:<\/span><br \/>\n<code>0.81 0.13 0.69 0.17 0.01 0.73 0.49 0.57 0.21 0.33 0.29 0.97 0.41 0.93 0.09 0.37 0.61 0.53 0.89 0.77 0.81 0.13 0.69 0.17 0.01 0.73.<br \/>\n<\/code><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s try to implement it using C++ tools. All necessary comments will be included:<\/span><\/p>\n<p>[code language=&#8221;cpp&#8221;]<br \/>\n#include &quot;stdafx.h&quot;<br \/>\n#include &lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>double pseudo(int &amp;); \/\/ prototype for pseudo-random function<\/p>\n<p>int main(int argc, char* argv[])\/\/comand prompt arguments<br \/>\n{<br \/>\n    const int amount = 25; \/\/ amount of pseudo-random numbers<br \/>\n          int x0 = 2; \/\/ starting value<br \/>\n    cout &lt;&lt; &quot;\\nPseudo-random:   &quot;;<br \/>\n    for (int i = 0; i &lt;= amount; i++)<br \/>\n        cout &lt;&lt; pseudo(x0) &lt;&lt; &quot; &quot;; \/\/ generate the i-th number<br \/>\n    cout &lt;&lt; &quot;\\n&quot;;<br \/>\n    system(&quot;pause&quot;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>double pseudo(int &amp;x) \/\/ generating pseudo-random numbers function<br \/>\n{<br \/>\n const int a = 100, \/\/ generating pseudo-random numbers from 0 to 100<br \/>\n           m = 8, \/\/ multiplier<br \/>\n         increment = 65; \/\/ increment value<br \/>\n x = ((m * x) + increment) % a; \/\/ out formula<br \/>\n return (x \/ double(m));<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Let\u2019s try to run the program. Here is what we get:<br \/>\n<code>Pseudo-random: 0.81 0.13 0.69 0.17 0.01 0.73 0.49 0.57 0.21 0.33 0.29 0.97 0.41 0.93 0.09 0.37 0.61 0.53 0.89 0.77 0.81 0.13 0.69 0.17 0.01 0.73<\/code><br \/>\nEverything works correctly. There are a lot of more complicated ways to implement the solution of this task, but in this guide we concentrated on the most simple one.<\/p>\n<p>Thanks for your attention!<\/p>\n<h2 style=\"text-align: center;\"><i><span style=\"font-weight: 400;\">Superior Help With Information Technology Assignments<\/span><\/i><\/h2>\n<p><i><span style=\"font-weight: 400;\">You can freely use this program for the<\/span><\/i><i> generation of pseudo-random numbers <\/i><i><span style=\"font-weight: 400;\">using C++ tools. Our samples are aimed to help you with conducting your own assignments more easily and effectively. Keep in mind that if you plan to take parts of our essay sample and include them in your own writing, you may be accused of plagiarism. If you were assigned an unmanageable assignment and you need assistance, don\u2019t be upset! Use AssignmentShark.com and professionals will take care of your papers.<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">If you are studying in an IT related course, you should pay a lot of attention to the practical part of your studying, and most likely you would like to apply the <\/span><\/i><i>generation of pseudo-random numbers <\/i><i><span style=\"font-weight: 400;\">using C++ tools in practice. We clearly understand that students don\u2019t want to waste time on monotonous and sometimes useless essays and reports. In any case, you can rely on our service in order to spend your time more effectively, and at the same time receive good grades. Our team of writers is able to complete any paper on any discipline, so be confident that your assignment will be in the hands of professionals. To make the order, you should fill in the order form and describe the requirements of your assignment, set the deadline, and add contact info. Our experts will put every effort into making your paper unique and of the best quality.\u00a0<\/span><\/i><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/do-my-computer-science-homework.html\" target=\"_blank\" rel=\"noopener\">Do my computer science assignment<\/a> right now!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Congruential Method of Formation of Pseudo-Random Numbers We need to program a generator of pseudo-random numbers using the congruential method of formation of pseudo-random numbers. Random numbers means the possible values xi of a continuous random variable X, distributed uniformly on the interval [0;1). The formula defining the congruential method of generating pseudo-random numbers is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-8052","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/8052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=8052"}],"version-history":[{"count":12,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/8052\/revisions"}],"predecessor-version":[{"id":12885,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/8052\/revisions\/12885"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=8052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=8052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=8052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}