

{"id":26,"date":"2026-05-29T00:25:28","date_gmt":"2026-05-29T00:25:28","guid":{"rendered":"https:\/\/apropostechsolutionscorp.ca\/blog\/?p=26"},"modified":"2026-06-13T03:25:57","modified_gmt":"2026-06-13T03:25:57","slug":"javascript-random-numbers","status":"publish","type":"post","link":"https:\/\/apropostechsolutionscorp.ca\/blog\/2026\/05\/29\/javascript-random-numbers\/","title":{"rendered":"JavaScript: random numbers"},"content":{"rendered":"\n<h2>JavaScript is a versatile language, even for testing. What about its random numbers?<\/h2>\n<p>\nThe following is from my reference frame:<\/p>\n<p>\nJavaScript has Math.random() to generate a random number between 0 and 1. However, it would be reassuring if one could seed the random number generator. Yet, it seems that Math.random() can&#8217;t be seeded by the user.<\/p>\n<p>\nIn connection, Mozilla suggests the crypto library: crypto.getRandomValues(input_array). The input_array needs to be a declared type, which was surprising to me: I don&#8217;t recall JavaScript being a typed language.<\/p>\n<p>\nThe following lines capture the idea of how one might use crypto.getRandomValues():\n<\/p>\n<div style=\"color:green\">\n<p><code>\nlet input_array = Int8Array(10); \/\/10 values\n<\/code><\/p>\n<p><code>crypto.getRandomValues(input_array);<\/code><\/p>\n<p><code>let a_random_value=input_array[3]; \/\/for example<\/code><\/p>\n<\/div>\n<p>\nJavaScript can be a fun language to experiment with:)<\/p>\n<p>\nSource:<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Math\/random\">developer.mozilla.org: Math.random()\n<\/a><\/p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Math\/random\">\n<\/a><p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Math\/random\"><\/a><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Crypto\/getRandomValues\">developer.mozilla.org: Crypto: getRandomValues method<\/a><\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Int8Array\">developer.mozilla.org: Int8Array<\/a><\/p>\n<p><a href=\"https:\/\/apropostechsolutionscorp.ca\/blog\/\">-JS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript is a versatile language, even for testing. What about its random numbers? The following is from my reference frame: JavaScript has Math.random() to generate a random number between 0 and 1. However, it would be reassuring if one could seed the random number generator. Yet, it seems that Math.random() can&#8217;t be seeded by the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,79],"tags":[8,7,6],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-javascript","category-programming","tag-crypto-getrandomvaluesarray","tag-math-random","tag-random-numbers"],"_links":{"self":[{"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":16,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/posts\/26\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apropostechsolutionscorp.ca\/blog\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}