jalutz Posted August 25, 2003 Posted August 25, 2003 For an upcoming promotion, I need to be able to select a customer at random. Each customer has a unique number in my FM data base. I'm trying to develop a script to accomplish that within FM. Possible? I have already created a field that I can mark customer records that are eligible (ie has an e-mail address and hasn't won before). The perfect script would only scan the selected records and randomly select a record which would become the "winner". Possible within FileMaker? -- jal
andygaunt Posted August 25, 2003 Posted August 25, 2003 Hi, You can do this using a set field and go to record commands in your script. Create a global number field (lets call it gRandom) to hold the result In your script add the following lines Set Field [gRandom, Round(Random* (Status( CurrentFoundCount) - 1) + 1, 0) ] Go To Record/ Request/ Page [by field value, gRandom] HTH
jalutz Posted August 25, 2003 Author Posted August 25, 2003 Very helpful! That accomplishes what I need. Thank you. -- jal
BobWeaver Posted September 4, 2003 Posted September 4, 2003 This formula keeps popping up from time to time, and it does not give an even probability for picking all records. The first and last record will always have exactly half the probability of being picked compared to the other records. To see what I mean, work out the math for a found set of 3 records. Random value in the range 0 to .24999 returns record 1 (25% chance) Random value in the range .25 to .74999 returns record 2 (50% chance) Random value in the range .75 to .9999 returns record 3 (25% chance) The culprit is the Round() function which skews the calculation. The correct (and simpler) formula should be: Int (Status(CurrentFoundCount)*Random)+1
Recommended Posts
This topic is 7754 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