title


easy.math.random(max)

easy.math.random() returns a random number from 0 to "max"


syntax:

easy.math.random(max)

source code:

random(max) { return Math.random() * max; }

start and end:

arguments:

  1. max (number):
    the maximum number to be randomly generated

returns:

Math.random() * max

a random number, natively 0-1, multiplied by "max"


example:

easy.document.search("#button").addEventListener('click', () => { window.alert(`your random number is ${easy.math.random(100)}`); });

the example above...

  1. adds a click event listener to an element with "button" id (see easy.document.search(query) f)
  2. upon clicked, an alert opens, telling the user their random number

combos:

  1. easy.math.limit(numb, min, max) f can be used to form a random number within a certain range
    heres an example:
    easy.math.limit(easy.math.random(10), 5, 10)
  2. easy.math.integer(numb) f can be used to form a random integer instead
    heres an example:
    easy.math.integer(easy.math.random(10))


see also:

  1. easy.math.limit(numb, min, max) f
  2. easy.math.integer(numb) f
  3. easy.document.search(query) f