DEV Community

ekaknl22
ekaknl22

Posted on

random value

how to create a limit with a random value function, for example a limit of 25-45?

Top comments (4)

Collapse
 
gauravgaur profile image
Gaurav Gaur

You can use something like

random_value = 25 + (45 - 25) * random();

Where random() is method call that generates a random number between 0 and 1. Usually every language supports some kind of random() implementation. You need to find this implementation in your preferred language.

(45 - 25) defines your range and the upper limit.

While adding 25 will ensure your lower limit.

Collapse
 
ekaknl22 profile image
ekaknl22

thank you so much

Collapse
 
jeremymonatte profile image
Mbenga

You want to do it in wich language ?

Collapse
 
ekaknl22 profile image
ekaknl22

c++