Page 1 of 1

Getting a random number between X and Y Real numbers

PostPosted: Mon Dec 20, 2021 9:27 pm
by joemart
I feel that this question involves more LUA than DR, but I will ask it anyway:

I'm trying to get a real number within specific parameters. Whenever I use the expression "random(0.0006, 0.0008)", I get an integer. How would I go and do a function that returns any real number from within given parameters if possible?

Re: Getting a random number between X and Y Real numbers

PostPosted: Tue Dec 21, 2021 1:49 am
by xunile
If you only want .0006 .0007 .0008 as your possible results, you could try the following code.

Code: Select all
math.random(6,8) / 1000

Re: Getting a random number between X and Y Real numbers

PostPosted: Tue Dec 21, 2021 1:58 am
by joemart
xunile wrote:If you only want .0006 .0007 .0008 as your possible results, you could try the following code.

Code: Select all
math.random(6,8) / 1000


Well, any real number between .0006 and .0008, for example .00061, .00062, .000601, .000602, etc. and how I would control the decimal spaces? I'm not sure how you can do this in LUA.

Re: Getting a random number between X and Y Real numbers

PostPosted: Tue Dec 21, 2021 12:41 pm
by brunocbreis
Code: Select all
math.random(6000,8000) / 1000000
worked for me! :D Add more zeros to both the numerator and the denominator for more precision

Re: Getting a random number between X and Y Real numbers

PostPosted: Tue Dec 21, 2021 3:38 pm
by joemart
brunocbreis wrote:
Code: Select all
math.random(6000,8000) / 1000000
worked for me! :D Add more zeros to both the numerator and the denominator for more precision


Brilliant! That works perfectly! Thank you!