Bob476 Posted March 15, 2004 Share Posted March 15, 2004 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? Link to comment Share on other sites More sharing options...
-Queue- Posted March 15, 2004 Share Posted March 15, 2004 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. Link to comment Share on other sites More sharing options...
CobaltSky Posted March 15, 2004 Share Posted March 15, 2004 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. Link to comment Share on other sites More sharing options...
-Queue- Posted March 15, 2004 Share Posted March 15, 2004 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. Link to comment Share on other sites More sharing options...
CobaltSky Posted March 16, 2004 Share Posted March 16, 2004 -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... Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 7345 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now