I was playing around to see if I could find a smart way with the Rnd function to generate random numbers deriving from numbers already containing decimals by multiplying the input by 100000000, knowing that it will have a max of 8 decimals, and dividing it afterwards by 100000000.
But because of the limits of integers, this does not work well. Is there any known smart way to do this?
Let me make it clear .. both the input low and high and the output should be with decimals.
I found a post with a function that almost does it, but it does not work on numbers with a value below 1.
Dim JORandom As JavaObject
JORandom.InitializeStatic("java.lang.Math")
Dim MinRange As BigDecimal
Dim MaxRange As BigDecimal
Dim Random As BigDecimal
Dim Range As BigDecimal
Dim Result As BigDecimal
MinRange.Initialize("0.5")
MaxRange.Initialize("2.5")
Range = MaxRange.Subtract(MinRange)
Random.Initialize(JORandom.RunMethod("random",Null))
Result = MinRange.Add(Range.Multiply(Random)).Round(8,MinRange.ROUND_HALF_UP)
Log(Result.ToPlainString)
No, what I needed was to generate random numbers with up to 8 decimal places.. for instance Rnd(0.00008922,8789321.08082789). But keirS has solved my problem!
Dim JORandom As JavaObject
JORandom.InitializeStatic("java.lang.Math")
Dim MinRange As BigDecimal
Dim MaxRange As BigDecimal
Dim Random As BigDecimal
Dim Range As BigDecimal
Dim Result As BigDecimal
MinRange.Initialize("0.5")
MaxRange.Initialize("2.5")
Range = MaxRange.Subtract(MinRange)
Random.Initialize(JORandom.RunMethod("random",Null))
Result = MinRange.Add(Range.Multiply(Random)).Round(8,MinRange.ROUND_HALF_UP)
Log(Result.ToPlainString)