March 15, 200421 yr I'm trying to create a field that will calculate a non-unique random number between a given range (1-8) for each record. That is, each record out of 125, for example, would each have a random value between 1 and 8 for that field. Solutions?
March 15, 200421 yr Truncate( Random* 7.1, 0 ) + 1 Adding 1 prevents 0 from being an option. Using 7.1 ensures adding 1 and truncating won't exceed 8.
March 15, 200421 yr If you require that the numbers be truly random (and therefore evenly distributed over a large sample) using 7.1 will not do, as it will ensure that the numbers 1 to 7 occur in the result with a frequency ten times that of the number 8. To achieve a random distribution of numbers from 1 to 8, I suggest you use: Int(Random * 8) + 1 The Random function produces a number between zero and 1 (not inclusive). Since it will never equal either 0 or 1, multiplying it by 8 will produce a result which extends from 0.0000000000000001 to 7.99999999999999 (once the floating point limitation of 15 decimal places in FMP v6 is applied to it). Applying Int( ) to this result will give an even distribution of integers from 0 to 7 inclusive, and only then will adding one give you the result you've asked for.
March 15, 200421 yr Well dang, it was nice of FM to include that little detail regarding exclusivity in their help file. Luckily I haven't had need to use random numbers in my business. I assume then, that Truncate(Random* 8, 0) + 1 would be satisfactory and similar to Int(Random* 8) + 1, though minorly more complex.
March 16, 200421 yr -Queue- said: Well dang, it was nice of FM to include that little detail regarding exclusivity in their help file. Luckily I haven't had need to use random numbers in my business. Yes. If it were inclusive, an unweighted distribution of results could be appropximated using Int(Random * 7.999) + 1. Not only is the online help entry on the Random function implicit rather than explicit, but the example it cites also contains several errors. I assume then, that Truncate(Random* 8, 0) + 1 would be satisfactory and similar to Int(Random* 8) + 1, though minorly more complex. Yep. Modestly over-engineered, but nonetheless effective...
Create an account or sign in to comment