{"id":6775,"date":"2021-10-07T14:09:51","date_gmt":"2021-10-07T05:09:51","guid":{"rendered":"https:\/\/learningbox.co.jp\/?p=6775"},"modified":"2021-10-07T14:10:16","modified_gmt":"2021-10-07T05:10:16","slug":"blog_php-random","status":"publish","type":"post","link":"https:\/\/learningbox.co.jp\/en\/2021\/10\/07\/blog_php-random\/","title":{"rendered":"Output near random values in PHP"},"content":{"rendered":"<p>Nice to meet you. My name is Nishikawa, and I joined the company in June.<br \/>\nIn this article, I will show you how to create a random number in PHP.<br \/>\nA random number is one that has no artifice in the sense that it is generally a value created \"at random\" without any law.<br \/>\nFor those who use PHP regularly, the mt_rand() function, which is called a pseudo-random function, is familiar.<\/p>\n<p>This function returns a random value depending on when it is executed.<br \/>\nIt is only omitted in the processing, but the seed value is set internally.<br \/>\nThe seed value is automatically set depending on the timing of processing, but you can keep returning the same value by fixing the seed value with mt_srand().<br \/>\nThis is the reason why it is called pseudo-random.<\/p>\n<p>As mentioned above, seed value is automatically assigned in php4.2 or later, so it is random.<br \/>\nIt is very useful. First, we will describe the generation of a commonly used random number.<\/p>\n<h2>ajax.php<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6777 size-full\" src=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax.png\" alt=\"\" width=\"856\" height=\"124\" srcset=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax.png 856w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax-300x43.png 300w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax-768x111.png 768w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax-16x2.png 16w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><br \/>\nUse mt_rand(), which we told you about at the beginning.<\/p>\n<h2>index.html<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6781 size-full\" src=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/index.png\" alt=\"\" width=\"847\" height=\"489\" srcset=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/index.png 847w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/index-300x173.png 300w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/index-768x443.png 768w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/index-16x9.png 16w\" sizes=\"auto, (max-width: 847px) 100vw, 847px\" \/>The HTML part above is provided to clarify the action of the person.<\/p>\n<p>\"The time between when the content is displayed and when the button is pressed is how people behave.<br \/>\nSome actions can further increase the randomness.<br \/>\nWe will create a random number based on the data sent from the HTML above.<\/p>\n<h2>ajax.php<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6783 size-full\" src=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax2.png\" alt=\"\" width=\"845\" height=\"170\" srcset=\"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax2.png 845w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax2-300x60.png 300w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax2-768x155.png 768w, https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/09\/ajax2-16x3.png 16w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/>Execute the ajax in the aforementioned HTML.<br \/>\nA random number is generated.<\/p>\n<p>By using this kind of processing, you can get more variation in the data than when using only mt_rand() to get random numbers. In actual implementation, it is possible to hide the seed value by processing it internally with php.<\/p>\n<p>The above implementation depends on the seed value and is not completely random, so it is not suitable for cryptographic processing.<\/p>","protected":false},"excerpt":{"rendered":"\u521d\u3081\u307e\u3057\u3066\u30016\u6708\u306b\u5165\u793e\u3057\u305f\u958b\u767a\u90e8\u306e\u897f\u5ddd\u3068\u7533\u3057\u307e\u3059\u3002 \u4eca\u56de\u306e\u8a18\u4e8b\u3067\u306f\u3001PHP\u3067\u4e71\u6570\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 [&hellip;]","protected":false},"author":38,"featured_media":6868,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"vkexunit_cta_each_option":"","footnotes":""},"categories":[7],"tags":[80,81,62,82],"class_list":["post-6775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-7","tag-ajax-php","tag-index-html","tag-php"],"acf":[],"jetpack_featured_media_url":"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/10\/PHP_1633583124.jpg","jetpack_shortlink":"https:\/\/wp.me\/pgMrZ4-1Lh","_links":{"self":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/comments?post=6775"}],"version-history":[{"count":27,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6775\/revisions"}],"predecessor-version":[{"id":6869,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6775\/revisions\/6869"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media\/6868"}],"wp:attachment":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media?parent=6775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/categories?post=6775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/tags?post=6775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}