JS: random number function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

JS: random number function

Dear All, I have 2 decisions of the task. We need the following goal: to make a function that gives you random numbers from min to max without floating point. The first decision is mine. The second is not. Could you please let me know, are they equal basically? What is better in global? The code is here: https://code.sololearn.com/WDLeojqSpmFU/?ref=app Thanks!

11th Apr 2020, 9:44 PM
Дмитрий Волошин
Дмитрий Волошин - avatar
1 Answer
0
UPD: One guy helped me - you can find it interesting. Please, see the code in attachment: https://code.sololearn.com/WB11RER3Yp6w/?ref=app This code tests my decision in 10000 iterations. It contains an array where: 1 - the first element 2 - the second element 3 - the third element. Function works but not correct because the probability of getting min and max values ​​is 2 times less than any other number. This inconvenience is caused because of rounding feature from floating point to integer. Thanks for your attention
12th Apr 2020, 8:07 PM
Дмитрий Волошин
Дмитрий Волошин - avatar