Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Random Number Generator for Unique, non-repeating numbers


NanetteS
 Share

Recommended Posts

I am building an Audiology database and my client wants to use a random number generator to select the which tests will be done in which order for each subject tested (one record). I am having issues making the random number generator come up with only one number in a field and not repeating a number in several fields. In other words, out of 7 test fields and numbers, I can end up with three 6's or two 2's. My Client uses this to determine on how the tests will be ordered and carried out that she does for her subjects.

I used one way of creating random numbers.

I went to the first test field PPRandNum and then went to RECORDS and down to REPLACE FIELD CONTENTS and selected "Replace with calculated result" and Specified: Int(Random * 7) +1

and hit replace. I filled this calculated result into all 7 test fields and got a number for each field between 1 and 7, which is what I wanted, but then again, I got duplicates, which I do not want.

Is there an easier way to do this?

I know if I can get this to work I can build a script to do it for each new record, but I would guess that it would change the other records that already exist (not sure but I am sure I will find out once I can get this working to be unique entries).

Any help would be appreciated.

Thanks,

Nanette

Link to comment
Share on other sites

Do you mean that you want different variations of the order of seven tests, so that the seven tests may be ordered 2, 7, 4, 5, 3, 1, 6? And then the next time the "Test Order" button is pushed another but different order is generated?

 

EDIT: Check out this link at Brian Dunning's list of custom functions. Just be sure that for each pass you subtract off the test chosen.

Link to comment
Share on other sites

Are the tests always the same for every subject (just rearranging the order), or will different subjects be given different tests? Are there always the same number of tests for each subject?

Link to comment
Share on other sites

  • 2 weeks later...

This is NanetteS - under a second name. Had issue with logging in. Yes the tests are the same 7 tests, but given to each subject in a different order each time. At least that is what they want. Test A, B, C, D, E, F, G with "say" A being test #3, B being Test #1, C being Test #6 and so on with no duplicates. The next subject, has the same tests, but given to them in a different order. She has been using an Excel sorting methods on a excel sheet but I an making her a database to put all this in and she wants them to be different for each person and in a different order with no duplicates. Any help with doing this would be appreciated. Thanks. NSuksta

Link to comment
Share on other sites

  • 2 weeks later...

I checked out the Brian Dunning link but this is not going to help me with what I am looking for. Can anyone else come up with what I need to do in order to develop a Random Number Generator for non-repeating numbers between 1 and 7 that can be run (probably with a script to run) for each record I generate for an Audiology database for 7 tests they are doing. I was able to figure out my other issue to their satisfaction. This in the only remaining issue for me?

Thank you,

N. Suksta

Link to comment
Share on other sites

It seems like a grab bag kind of problem. You've got numbers 1-7 in the bag, and each time you pull one out. The next grab can only result in one of the remaining numbers in the bag.

 

In order to do this in FileMaker, I'd suggest a list to hold the grab bag of numbers, and a loop to reduce the list. When initially populated, the list would look like:

 

1

2

3

4

5

6

7

 

 

Then each time have a random number drawn, make it some value between the first value and the last value int(random*valuecount($theList))+1 [untested]. The value would be read with GetValue() and removed from the grab bag with LeftValues() and RightValues() (or a custom function).

 

So for example, if the 3rd value is drawn the list would become:

 

1

2

4

5

6

7

 

Then if the 3rd value is drawn again (4), the list would become:

 

1

2

5

6

7

 

With each iteration, the number of values in the list is reduced, leaving only the numbers that are still unclaimed.

 

It sounds like you've got seven fields to populate with these numbers. In this case, I'd make sure the fields are named with the number in the name (Test1, Test2, etc.) and use Set Field by Name[] to populate the correct one. The calc for the field name would be:

 

"Test" & $i

 

where $i is the loop counter.

 

Does that get you far enough along? Maybe you can share the script you end up with.

Link to comment
Share on other sites

Another algorithm that would work is to build a list of randomized numbers, then iterate though them to set the fields. This is simpler scripting IF you have an easy way to build the list of randomized numbers, a la a custom function (requires FileMaker Advanced). For example, Ray's ShuffleValues() CF could easily be fixed for FM 8.5+ compatibility by changing "List" to "theList", then use that to randomized the list of numbers. The script would then be something like:

 

Set Variable [$randomizedList ; ShuffleValues("1¶2¶3¶4¶5¶6¶7")]

Loop

Exit Loop If [ isempty($randomizedList) ]

Set Field by Name [ "Test" & valuecount($randomizedList) ; rightvalues($randomizedList; 1) ]

Set Variable [$randomizedList ; leftvalues($randomizedList; valuecount($randomizedList)-1) ]

End Loop

Link to comment
Share on other sites

 Share



×
×
  • Create New...

Important Information

Terms of Use