Jump to content

Need Random Calc within 1-8 Range


This topic is 6522 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

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. wink.gif

Link to comment
Share on other sites

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

-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... wink.gif

Link to comment
Share on other sites

This topic is 6522 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.