butiran

fun with random number

introduction

random function

There is a function to generate random float number ( MND, 2023 )

The Math.random() static method returns a floating-point, pseudo-random number that’s greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.

random number $\in [0, 1)$

integer random number

// set repetition
N = 40;

// set range of integer
imin = 2;
imax = 9;


// create empty array
a = [];

// generate random number
for(var i = 0; i < N; i++) {
  x = Math.random();
  y = x * (imax - imin + 1) + imin;
  z = Math.floor(y);
  a.push(z);
}

console.log(a);

randint in-house function

application(s)