
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate n random numbers between a range and pick the greatest in JavaScript
We are required to write a JavaScript function that takes in an array of two numbers as the first argument, this array specifies a number range within which we can generate random numbers.
The second argument will be a single number that specifies the count of random numbers we have to generate.
Then at last our function should return the greatest all random numbers generated.
Example
The code for this will be −
const range = [15, 26]; const count = 10; const randomBetweenRange = ([min, max]) => { const random = Math.random() * (max - min) + min; return random; }; const pickGreatestRandom = (range, count) => { const res = []; for(let i = 0; i < count; i++){ const random = randomBetweenRange(range); res.push(random); }; return Math.max(...res); }; console.log(pickGreatestRandom(range, count));
Output
And the output in the console will be −
25.686387806628826
- Related Questions & Answers
- Generating n random numbers between a range - JavaScript
- Generate random characters and numbers in JavaScript?
- How to generate random whole numbers in JavaScript in a specific range?
- How to generate random numbers between two numbers in JavaScript?
- Python Generate random numbers within a given range and store in a list
- Java Program to generate n distinct random numbers
- Python program to generate random numbers within a given range and store in a list?
- Java program to generate random numbers within a given range and store in a list
- Generate random numbers in Arduino
- Armstrong numbers between a range - JavaScript
- Get Random value from a range of numbers in JavaScript?
- How can I generate random numbers in a given range in Android using Kotlin?
- Generate pseudo-random numbers in Python
- Generate Random Integer Numbers in Java
- Generate random numbers using C++11 random library
Advertisements