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.
1
Function sbRndDecPlace(dmin As Double, dmax As Double, _
2
Optional ldecplaces As Long = 0) As Double
3
'Creates a random number between dmin and dmax with
4
'ldig decimal places. All possible (dmax - dmin) *
5
'10 ^ ldig + 1 values appear with same likelihood.
6
'https://berndplumhoff.gitbook.io/sulprobil/excel/excel-vba-solutions/sbrnddecplace
7
'V0.3 28.08.2020 (C) (P) by Bernd Plumhoff
8
Static bRandomized As Boolean
9
If Not bRandomized Then
10
Randomize
11
bRandomized = True
12
End If
13
sbRndDecPlace = Int((dmax - dmin + 10 ^ -ldecplaces) * _
14
10 ^ ldecplaces * Rnd) * 10 ^ -ldecplaces + dmin
15
End Function
Copied!
sbRndDecPlace.xlsm
16KB
Binary
Last modified 1yr ago
Copy link