A general (maths?) question about RandonFloatInRange

Hello. I’m using RandonFloatInRange to vary the pitch of a sound effect. It works well, but I would like to understand it better.

How many numbers would appear to the right of the decimal point in these random numbers? Is that set by the range numbers you give the expression?

In other words, if my range is (1.5, 2.5), are number like 1.5654 and 2.2344 possible, or are the random numbers limited to 1.6, 1.7, 1.8 etc. because of the numbers I provided?

So if I gave the range (1.6666, 2.9999), I would get numbers like 2.1234. Is that right?

Thank you (from a not-good-at-maths person).

I just tested and regardless of the precision you gave it, it returns a float 64 that is like 16 decimal digits.

1 Like

Crikey, that’s incredible granular! Thank you.

Edit: Seems I can limit the decimal places of the random number using round(number, number), like this:

roundTo(RandomFloatInRange(1.0, 1.5),1)

The ‘,1’ is how many decimal digits you want. So this expression can only produce 1.0, 1.1, 1.2, 1.3, 1.4 and 1.5.

Edit 2: @suh My apologies: after your reply I realised I could test it myself using a text object to show the random numbers. Thanks for nudging me along in the right direction.

1 Like

Or also the “intended” way RandomWithStep(1,1.5,0.1)

Returns 1, 1.1, 1.2, 1.3, 1.4, 1.5

1 Like

That’s brilliant, thank you. More concise than my approach too.

1 Like