You were very close, what you need is not to work with decimal numbers as min and max. Let's have max = 1000 and min = 100, so after your Math.floor you will need to divide by 100:

var randomnum = Math.floor(Math.random() * (1000 - 100) + 100) / 100;

Or if you want to work with decimals:

var precision = 100; // 2 decimals
var randomnum = Math.floor(Math.random() * (10 * precision - 1 * precision) + 1 * precision) / (1*precision);
Answer from Observer on Stack Overflow
🌐
CoreUI
coreui.io › blog › how-to-generate-a-random-number-in-javascript
Javascript Random - How to Generate a Random Number in JavaScript? · CoreUI
April 16, 2024 - Math.random() is a powerful tool in JavaScript that generates a pseudo-random number—a number that seems random but is actually generated through a deterministic process. It returns a floating-point, or decimal, number between 0 (inclusive) ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-generate-random-number-in-given-range-using-javascript
Generate Random Number in Given Range Using JavaScript - GeeksforGeeks
July 11, 2025 - Use the same scaling and shifting method to generate decimals within the specified range. To generate random numbers within predefined ranges, arrays can help organize the ranges and randomize the selections.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-random-number-how-to-generate-a-random-number-in-js
JavaScript Random Number – How to Generate a Random Number in JS
August 3, 2022 - The general syntax for generating a decimal between two values (or range) looks something similar to this: ... // specify a minimum - where the range will start let min = 20.4; // specify a maximum - where the range will end let max = 29.8; I created two variables, min and max - where min will be the smallest number and max the biggest number in the range. Next, I generate a random number within that range using the syntax you saw earlier on:
🌐
Educative
educative.io › answers › how-to-generate-random-whole-numbers-in-javascript
How to generate random whole numbers in JavaScript
In this shot, we will learn to generate random numbers in JavaScript. In JavaScript, the Math.random() function generates random decimal numbers. The numbers generated are between 0, which is inclusive, and 1, which is exclusive.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › random
Math.random() - JavaScript - MDN Web Docs - Mozilla
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 ...
🌐
Udacity
udacity.com › blog › 2021 › 04 › javascript-random-numbers.html
Creating Javascript Random Numbers with Math.random() | Udacity
September 27, 2022 - Then we’ll move onto ways of obtaining higher-quality random data; your needs will determine the worthwhile effort. Javascript creates pseudo-random numbers with the function Math.random(). This function takes no parameters and creates a random ...
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › random-examples.html
Math.random Examples — Introduction to Professional Web Development in JavaScript documentation
... If a random integer must be generated, the result of Math.random() can be manipulated with operators (+, -, *, /) and other Math methods. The trick to creating a random integer is to multiply Math.random() by a whole number and then round the result to remove the decimal portion.
Find elsewhere
🌐
DEV Community
dev.to › shimphillip › working-with-random-numbers-in-javascript-1c0k
Working with random numbers in JavaScript - DEV Community
July 29, 2019 - Let's first run Math.random() in a console. Math.random() // 0.34484257625111736 · Math.random() returns a floating number(number with decimal) between 0 (inclusive) and 1(exclusive).
🌐
Reintech
reintech.io › blog › tutorial-working-with-math-random-method
Working with the Math.random() Method | Reintech media
February 22, 2023 - Here's an example of how to generate a random number between 1 and 10: This code will generate a random integer between 1 and 10 and log it to the console. You can also use the Math.random() method to generate a random decimal between two numbers.
🌐
SitePoint
sitepoint.com › blog › javascript › how to generate random numbers in javascript with math.random()
Generating Random Numbers in JavaScript with Math.random()
November 7, 2024 - At the time of writing, all the major browsers currently use the xorshift128+ algorithm in the background to generate a pseudo-random number. To use it, simply enter Math.random() and it will return a pseudo-random floating point decimal number ...
🌐
Markaicode
markaicode.com › home › javascript › how to generate random numbers in javascript (5 methods that actually work)
How to Generate Random Numbers in JavaScript (5 Methods That Actually Work) | Markaicode
September 4, 2025 - Generate random numbers, integers, and arrays in JavaScript. Copy-paste code with real examples. Save 2 hours of debugging weird edge cases.
🌐
DEV Community
dev.to › theudemezue › how-to-generate-random-numbers-in-javascript-6ae
How To Generate Random Numbers In JavaScript - DEV Community
March 8, 2025 - When it comes to creating random numbers in JavaScript, the most commonly used function is Math.random(). This built-in method returns a floating-point number between 0 (inclusive) and 1 (exclusive).
🌐
Reintech
reintech.io › term › generate-random-decimals-javascript
Generating Random Decimals using JavaScript | Reintech media
With JavaScript's Math.random() method, developers have the ability to generate random decimal numbers between two values. This is achieved by taking the result of Math.random(), multiplying it by the difference of the two numbers, and then ...
🌐
Stack Abuse
stackabuse.com › javascript-generate-random-number-in-range
JavaScript: Generate Random Number in Range
September 21, 2023 - We will also touch upon a few built-in ... use by writing a function to simulate a six-sided die. Math.random() in JavaScript generates a floating-point (decimal) random number between 0 and 1 (inclusive of 0, but not 1)....
🌐
Iifx
iifx.dev › english › javascript
JavaScript Random Number Generation: A Comprehensive Guide
JavaScript provides a built-in function, Math.random(), to generate a random decimal number between 0 (inclusive) and 1 (exclusive).
🌐
Better Programming
betterprogramming.pub › generating-random-numbers-in-javascript-4b2a1e9d1806
Generating Random Numbers in JavaScript
December 1, 2019 - The Math.random() will generate a pseudo-random floating number (a number with decimals) between 0 (inclusive) and 1 (exclusive).