Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to generate a random number from 10 to 100 by js

Shulou Source: shulou.com Published: 2022-05-31 10:38:50 10月03日 Update

This article mainly introduces "how to generate a random number from 10 to 100 by js". In daily operation, I believe that many people have doubts about how to generate a random number from 10 to 100 by js. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the question of "how to achieve random numbers to generate a number from 10 to 100 by js". Next, please follow the editor to study!

1. Generating random number method

/ / this example represents the random number function getRandomNum (Min,Max) {var Range = Max-Min;var Rand = Math.random (); return (Min + Math.round (Rand * Range));} var num = GetRandomNum (10100); console.log (num)

2.random () function method

The returned value is the value of double type. Because of its high accuracy, it can be regarded as a random number to a certain extent. With the help of (int), you can get a random integer number. The code is as follows.

Public static void main (String [] args) {int max=100,min=10;int ran2 = (int) (Math.random () * (max-min) + min); System.out.println (ran2);} at this point, the study on "how to generate a random number from 10 to 100 by js" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Random numbers generation number learning numerical more help practical next code representatives examples functions integers articles methods theory knowledge degree article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Redmi Shulou Technology macOS