stann Posted May 24, 2004 Posted May 24, 2004 Hello I have a file with a field "rangebegin" and a field "rangeend" I want to have a field called "usednumbers" and a field called "NUMBER" I am in filemaker 7; I would like to have a script that would pick a new number from within the range of "rangebegin & rangeend" make sure that each time it picks a new number. Can someone help me with this one. Thanks very very much Stann
Ender Posted May 24, 2004 Posted May 24, 2004 I've been working on a similar thing for slotting staff into random training groups. This is the algorithm I've come up with: Set Field [ "Number" , "Int(Random*RangeEnd) + RangeBegin" ] //Get a random number in the range Loop If ["isempty(RangeEnd) or RangeEnd < RangeBegin" ] //Error Exit Script End If Exit Loop If [ "PatternCount(gNumbersUsed, Number)" ] //A empty slot found Set Field [ "Number" , "Number +1" ] //Try the next number up If [ "Number > RangeEnd" ] //Reached the end of the range, start over at the start of the range Set Field [ "Number" , "RangeBegin" ] End If End Loop Set Field [ "gNumbersUsed", "gNumbersUsed & " "& Number" ] When it tries a number that has already been used, it sequentially tries the next greater number. This doesn't feel as random as trying another random number, but it's more efficient.
zincb Posted May 24, 2004 Posted May 24, 2004 Assuming you only want integer values, for the random, you could also use: MyRandomNumber = Round( Random * ( Table_1::RangeEnd - Table_1::RangeBegin ) ; 0 ) + Table_1::RangeBegin Attached is a quick file to illustrate. zippy.zip
stann Posted May 24, 2004 Author Posted May 24, 2004 Thank you both , I have a question though How can I in response to Zincb's example keep it from using the same number twice. That is very important in this case. I need help with this. thanks Stan
stann Posted May 24, 2004 Author Posted May 24, 2004 also , If my range is 1-300 is there a way to keep a three number figure like 003,055, 104, 298, 007 , 018, 214 etc.
Fitch Posted May 24, 2004 Posted May 24, 2004 Another approach you might consider is to use a table with say, 999 records. Each record has a field for your number, which should be a TEXT field if you want to use leading zeroes. A second field would contain a corresponding serial number, which we will use for a lookup. What your script would do is generate a random number in the range, and then use that number to do a lookup on the table above. If no match is found, it selects the next higher value. Then clear the serial number field so that the next lookup won't use it. I.e., clearing the serial number marks the number as "used."
zincb Posted May 24, 2004 Posted May 24, 2004 Sorry, I didn't fully comprehend your question in my last reply. Attached is a modified file that gives you up to 9 leading zeros, and will allow you to select just a few numbers at a time. randomizer.zip
stann Posted May 24, 2004 Author Posted May 24, 2004 I am sorry zincb but I can't enter any numbers in the file you attached. I don't know what is wrong. I go to rangeend or rangebegin and It will not allow me to add numbers?
zincb Posted May 25, 2004 Posted May 25, 2004 I learn something new every day! Evidently FM7 defaults to a Guest account with read-only rights, which have to be changed to allow "modify" access. More default security, I suppose, but I sort of liked only having to secure things that were vital. We are Borg; the Collective will adapt. Please try the attached file. randomizer2.zip
stann Posted May 25, 2004 Author Posted May 25, 2004 I am not sure that is it. I went into privs and put the account to full access but it is not letting me enter anything into the file. Stann
Boto Posted May 25, 2004 Posted May 25, 2004 Not the solution in here just a question that can bring some light in this situation... Okay so you want to assign unique random numbers to a number of records... but is it like you have 200 records and want to appoint the numbers 000 to 200 in random order, or is it more like 50 records and appoint a random value from 0000 to 9999.. Cause in situation 1, you might want to look to a reversed approach, adding 001 to a random record and then adding 002 and so on.... cause the chance the random generator generates a valid integer in situation 1 near the end of the cycle is about 0,5%... imagine what the searchtime would be with 10.000+ integers and the same amount of records.
zincb Posted May 26, 2004 Posted May 26, 2004 stann said: I am not sure that is it. I went into privs and put the account to full access but it is not letting me enter anything into the file. Stann I may be getting distracted from the original post, but this is getting very curious. Did you download the second file I posted (#106879 - 05/25/04 06:58 AM) or are you talking about the first one? In the second file, I set the [Guest] account to "Full Access", so you should have been able to do anything, up through complete destruction. One thought -- I created the file on a Windows 2000 box -- what platform are you running on?
Recommended Posts
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