{"id":5,"date":"2020-07-15T13:07:20","date_gmt":"2020-07-15T06:07:20","guid":{"rendered":"https:\/\/luthfishahab.com\/?p=5"},"modified":"2020-07-15T13:07:20","modified_gmt":"2020-07-15T06:07:20","slug":"create-random-permutation","status":"publish","type":"post","link":"https:\/\/notes.its.ac.id\/luthfishahab\/create-random-permutation\/","title":{"rendered":"Create Random Permutation"},"content":{"rendered":"\n<p>In this post, I provide a simple code to create a random permutation in an array of length&nbsp;<em>n<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public int&#091;] getRandomPermutation(int n) {\n    int a&#091;] = new int&#091;n];\n \n    \/\/ Initialize the array\n    for (int i = 0; i &lt; n; i++)\n        a&#091;i] = i;\n \n    \/\/ Shuffle the array\n    for (int i = 0; i &lt; n; i++) {\n        \/\/ Generate an index randomly\n        int index = (int)(Math.random() * n);\n        int temp = a&#091;i];\n        a&#091;i] = a&#091;index];\n        a&#091;index] = temp;\n    }\n \n    return a;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h1 class=\"gb-headline gb-headline-fa2dc974\">Create Random Permutation<\/h1>\n\n\n\n<p class=\"gb-headline gb-headline-cb10130b\">In this post, I provide a simple code to create a random permutation in an array of length\u00a0<em>n<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I provide a simple code to create a random permutation in an array of length&nbsp;n.<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.its.ac.id\/luthfishahab\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}