Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript true random

function rand(min, max){
    return (Math.floor(Math.pow(10,14)*Math.random()*Math.random())%(max-min+1))+min;
}

// testing rand
function rollRands(min, max, rolls) {
    let roll = 0, n = 0;
    let counts = {};
    
    for(let i = min; i <= max; i++){
        counts[i]=0
    }

    while (roll < rolls){
        roll++;
        counts[rand(min,max)]++;
    }
    return counts;
}
  
console.log(rollRands(36, 42, 1000000));
 Run code snippetHide results
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript isalphanumeric 
Javascript :: react native button top right 
Javascript :: Object.hasOwnProperty.call 
Javascript :: add react to existing project 
Javascript :: javascript take last n elements of array 
Javascript :: how to update the react version in next js app 
Javascript :: convert date format from yyyy-mm-dd to dd-mm-yyyy using value javascript 
Javascript :: change index array javascript 
Javascript :: useSearchParams 
Javascript :: currying javascript sum 
Javascript :: check template shopify 
Javascript :: What is the syntax to export a function from a module in Node.js 
Javascript :: multiple import react js 
Javascript :: how to check all values of an array are equal or not in javascript 
Javascript :: regular expression for thousand separator 
Javascript :: js pass object property as a function parameter 
Javascript :: custom attribute jquery selector 
Javascript :: discord.js edit message by id 
Javascript :: javascript function loop through array 
Javascript :: regular expressions password contains number 
Javascript :: add value to each object in array javascript 
Javascript :: javascript get all characters before a certain one 
Javascript :: append row javascript 
Javascript :: readfile nodejs 
Javascript :: boolean constructor js 
Javascript :: ajax syntax in javascript 
Javascript :: javascript two digits number 
Javascript :: download jquery 
Javascript :: iterate through array js 
Javascript :: if classlist contains js 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =