Sulprobil
Search…
sbRndDecPlace
If you need to generate a random number between a defined minimal and maximal value with a specified number of decimal places, you can use this UDF.
Please read my Disclaimer.
Function sbRndDecPlace(dmin As Double, dmax As Double, _
Optional ldecplaces As Long = 0) As Double
'Creates a random number between dmin and dmax with
'ldig decimal places. All possible (dmax - dmin) *
'10 ^ ldig + 1 values appear with same likelihood.
'https://berndplumhoff.gitbook.io/sulprobil/excel/excel-vba-solutions/sbrnddecplace
'V0.3 28.08.2020 (C) (P) by Bernd Plumhoff
Static bRandomized As Boolean
If Not bRandomized Then
Randomize
bRandomized = True
End If
sbRndDecPlace = Int((dmax - dmin + 10 ^ -ldecplaces) * _
10 ^ ldecplaces * Rnd) * 10 ^ -ldecplaces + dmin
End Function
sbRndDecPlace.xlsm
16KB
Binary
Last modified 2yr ago
Copy link