{"id":371,"date":"2018-10-09T11:03:42","date_gmt":"2018-10-09T01:03:42","guid":{"rendered":"https:\/\/ghiassy.net\/?p=371"},"modified":"2018-10-09T11:11:52","modified_gmt":"2018-10-09T01:11:52","slug":"371","status":"publish","type":"post","link":"https:\/\/ghiassy.net\/?p=371","title":{"rendered":"Random Numbers C++17"},"content":{"rendered":"<p><span style=\"color: #00ff00;\">Hello!!<\/span><\/p>\n<p><span style=\"color: #00ff00;\">It\u2019s been a while that I have posted something here\u2026. Today I was reading new C++ book with 2017 standards. It\u2019s amazing how fast things been changing in C++ and it\u2019s evolving quickly.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">Even-though changing the habit is hard, I like where C++ is going to.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">Here is an example of Generating Random Numbers in C++17 Standards:<\/span><\/p>\n<pre class=\"lang:c++ decode:true \" title=\"C++17 Random Numbers\">\/*\r\n *\/\r\n\r\n#include &lt;cstdlib&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;string&gt;\r\n#include &lt;stdlib.h&gt;     \/* srand, rand *\/\r\n#include &lt;time.h&gt; \r\n#include &lt;algorithm&gt;\r\n#include &lt;random&gt;\r\n\r\nusing namespace std;\r\nint main(int argc, char** argv) {\r\n    \r\n    vector&lt;int&gt; x;\r\n    \r\n                random_device rd{};\r\n        \/\/engine and init with random seeds\r\n\tauto mtgen = std::mt19937{ rd() };\r\n\tauto ud = std::uniform_int_distribution&lt;&gt;{ 1,100 };   \/\/old way  -&gt; rand()%10+ 1 -&gt; range from 1 to 10\r\n\tfor (auto i = 0; i &lt; 20; i++)\r\n\t{\r\n\t\tauto number = ud(mtgen);\r\n\t\tx.push_back(number);\r\n\t}\r\n    \r\n    \r\n    std::cout &lt;&lt; \"Normal Order: \" &lt;&lt; endl;\r\n    \r\n    for(auto &amp;y: x)\r\n    {\r\n        cout &lt;&lt; y &lt;&lt; endl;;\r\n    }\r\n    \r\n    cout &lt;&lt; \"Reverse order:\" &lt;&lt; endl;\r\n    \r\n    std::reverse(x.begin(), x.end());\r\n    \r\n    for(auto &amp;z: x)\r\n    {\r\n        cout &lt;&lt; z&lt;&lt; endl;\r\n    }\r\n    std::sort(x.begin(), x.end());\r\n    \r\n    cout &lt;&lt; \"Sorted order:\" &lt;&lt; endl;\r\n\r\n   for(auto &amp;z: x)\r\n    {\r\n        cout &lt;&lt; z&lt;&lt; endl;\r\n    }\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #00ff00;\">In addition, if you are curious about the book I am reading here is the link to it; It\u2019s great book and I would highly recommend it.<\/span><\/p>\n<div style=\"width: 232px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.amazon.com\/dp\/1786465183\/ref=tsm_1_fb_lk\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/images-na.ssl-images-amazon.com\/images\/I\/51yTuWAIxGL._SX404_BO1,204,203,200_.jpg\" alt=\"\" width=\"222\" height=\"273\" \/><\/a><p class=\"wp-caption-text\"><span style=\"color: #00ff00;\">Modern C++ Programming Cookbook<\/span><\/p><\/div>\n<p><span style=\"color: #00ff00;\">All the best \ud83d\ude42\u00a0<\/span><\/p>\n<p><span style=\"color: #00ff00;\">\u2013 Saeed<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello!! It\u2019s been a while that I have posted something here\u2026. Today I was reading new C++ book with 2017 standards. It\u2019s amazing how fast things been changing in C++ and it\u2019s evolving quickly. Even-though changing the habit is hard, I like where C++ is going to. Here is an example of Generating Random Numbers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-371","post","type-post","status-publish","format-standard","hentry","category-c","category-programming"],"_links":{"self":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=371"}],"version-history":[{"count":5,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}