Learn how to get a random number without using Math.rand()
The Crypto.getRandomValues() method lets you get cryptographically strong random values.
Syntax: getRandomValues(typedArray)
Argument: typedArray β Is an integer-based TypedArray, which can be an Int8Array or an Uint8Array or an Int16Array or a Uint16Array or an Int32Array or a Uint32Array. All elements in the array are going to be filled with random numbers.
The follow example will generate an array of 10 random integers. You can modify this to your needs.

If you need a single value, you simply create an array of length 1 or access the first element typedArray[0].
The typed array is filled with random values, the max value in the above example is 2βΈ-1 because we are passing Uint8Array. If we pass UInt16Array then the array is filled with the max value of 2ΒΉβΆ- 1.
To get random values between 0 to 1 then you can divide the result by respective typedArray maxValue. If we use UInt8Array then we need to divide the value by (Math.pow(2,32)-1).
To learn about how to get a random number in the old way read here.
If you find this helpful surprise π me here.
Share if you feel happy π π πΒ .
Follow Javascript Jeepπ if you feel worthy.