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’t be seeded by the user.
In 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’t recall JavaScript being a typed language.
The following lines capture the idea of how one might use crypto.getRandomValues():
let input_array = Int8Array(10); //10 values
crypto.getRandomValues(input_array);
let a_random_value=input_array[3]; //for example
JavaScript can be a fun language to experiment with:)
Source:
developer.mozilla.org: Math.random()
developer.mozilla.org: Crypto: getRandomValues method
Leave a Reply