“Javascript Randint” Kode Jawaban

JavaScript mendapatkan nomor acak dalam jangkauan

function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

//usage example: getRandomNumberBetween(20,400); 
Grepper

angka acak sudut antara 1 dan 10

function randomNumber(min, max) {
  return Math.random() * (max - min) + min;
}
Disturbed Duck

JS Random Int

function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
JonnyG

JavaScript Nomor acak dalam kisaran

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
Sore Sandpiper

JavaScript int acak

//Returns random Int between 0 and 2 (included)
Math.floor(Math.random()*3)
Gubo97000

Javascript Randint

/* If 1 argument is given, minimum will be set to 0 and maximum to this argument
 * If 2 arguments were given, the fist would be the minimum and the second the maximum
 * The function will return an integer in [min, max[
 */
const Math.randint = function (min,max) {
  [min,max] = (max===undefined)?[0,min]:(min>max)[max,min]:[min,max];
  return Math.floor(Math.random*(max-min)+min);
}
Thoughtful Trout

Jawaban yang mirip dengan “Javascript Randint”

Pertanyaan yang mirip dengan “Javascript Randint”

Lebih banyak jawaban terkait untuk “Javascript Randint” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya