fnRandom ( minValue ; maxValue )
A better random, between a min and max value
Average rating: 4.7 (24 votes) Log in to vote
Rob Poelking - Show more from this author
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
I have always found FileMaker's built in Random function completely useless on it's own. Not that the function IS useless, but the random value I always needed was some whole integer. So I was always multiplying it and rounding it. Other times, I needed values that were between a minimum and a maximum. This function solved that particular issue for me.
The problem with the suggested calculation minValue + Round ( Random * ( maxValue - minValue + 1 ); PrecisionDigits ) was that if min and max are 1 and precision is 0, then you could get 2 erroneously.
Jan 1, 2014
Couldn't it be simpler?
minValue + Int ( Random * ( maxValue - minValue + 1 ) )
Dec 2, 2016
|VR - just discovered an error that when min and max are both 1 and precision is 0, then you could get 2 as a result which would be wrong. I know you're thinking, why would you ever do that but programmatically fetching a random value that could cycle down (as in a loop) you could get the wrong value.|
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.