Jump to content
Server Maintenance This Week. ×

Random-Systematic Script/Calc


Jim Gill

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

Recommended Posts

I have a script that schedules children, based on their choices, into six class periods per day. We call these class periods "Focuses" (just so you understand the verbiage in the script). My staff had been giving me feedback that the the morning focuses attendance was jammed full and the afternoon was slack. This made sense because the script would schedule kids systematically starting at focus 1 filling the classes to focus 6. So I wrote a sub-script (Attached) that would randomize the order in which each focus was scheduled, so the kids were distributed into each class equally throughout the day. This works well but the this sub-script REALLY bogs the overall progress of the main script.

There has to be an easier way (have a look at the attached). Here is what I need:

A calculation/script that randomize numbers 1 to 6 (example: 4, 1 3, 2 6, 5) - no repeats. I don't care if the results appear in a single field or across six different fields.

Any help is much appreciated!

Just an FYI: I'm not a developer - go easy on me! I'm just a camp director that loves this stuff!

Thanks,

Jim

Random Distridution Across Class.pdf

Link to comment
Share on other sites

Raybaudi has the right idea. Rather than calculating the trial-and-error random number generation until you get unique values within your range, you should start with the list of enumerated possible values (1, 2, 3, 4, 5, 6), and randomize the order of them. The function Raybaudi referenced could work with the right parameters:

NoRepDigit ( 6 ; 6 )




But my first instinct is more like this:




ValueShuffle ( List ( 1 ; 2 ; 3 ; 4 ; 5 ; 6 ) )

... with the ValueShuffle custom function here. This function will work better if you have numbers larger than 10 as possibilities or if you have text values you need to randomize the order of. With NoRepDigit, you can extract the returned values in order with the Middle function. With ValueShuffle, you can use GetValue.

As a side note, I saw that your script made extensive use of the Insert Calculated Result script step. Set Field is nearly always the better choice, since the target field does not have to be on the current layout for it to work.

  • Like 1
Link to comment
Share on other sites

I guess I do not understand the need. If there are only 6 focus groups (and probably more than 6 students) then a single focus number (between 1 and 6) must be repeated through the student list, right? Whether a group number repeats should not matter since you want random and random CAN repeat. If you for sure do not want a repeat then why not just number them 1 through 6 over and over down the list?

Also, what is the max number of Students a focus group can hold? If you use Random() isn't there a possibility that a single group will be overbooked? Anyway, I've created a script which assigns to the students in case Daniele and Jeremy's suggestions don't fit the bill.

You can also just make it a calculation and display your list of Students and you have your random 1-6 answer. If a calculation, any screen refresh will change the random number so you should print the list or write to field if you need to preserve it.

UPDATE: I added second script which assigns full list to each student and keeps them unique and removed extra variable. Version 11 and 12 are included in case someone has 11 instead.

RandomMOD.zip

Edited by LaRetta
  • Like 1
Link to comment
Share on other sites

Thanks you all! "Side Note" noted Jeremy - thanks! LaRetta - You nailed it for me - thank you so much!!

To your questions:

The main script schedules campers by their activity choices. There are parameters which must be met for the camper to be scheduled into each class including capacity limits. We have over 200 campers and up to 40 classes per focus period. Lets say 80 campers chose Gymnastics as there # 1 choice. The capacity max for gymnastics is 20 kids per focus. So what was happening, prior to the introduction of the sub-script you just helped me with, was gymnastics focus periods 1 - 4 were maxed to capacity and then I had 3 staff members with the nothing to do the last 2 focus periods (5 &6) of the day.

So with the introduction of the above sub-script, filemaker will try to schedule each camper into random systematic focus periods to distribute the class load throughout the day. Hopefully this makes sense - thank you again!

Link to comment
Share on other sites

"The capacity max for gymnastics is 20 kids per focus."

I started with relational approach but switched to list in Student record, LOL. Relational is better because a Classes table can hold numeric Capacity. An Assignments table would join them and hold the date, TeacherID, StudentID, ClassID. Script would create 6 records instead of lines per Student and random fill (but never exceed) a Class' capacity.

Students ---< Assignments >--- Classes.

In fact you probably have much of this in place already. BTW, those custom functions will achieve the same result as an inner loop (and faster if record sets are quite large) but script seemed simplest approach here. :wink3:

Link to comment
Share on other sites

Hi LaRetta,

So a loop is same as iteration and since you can pass the results to variable in the Let() to be used in the next iteration, what you show in your file in that inner loop is actually recursion. Is this right? I have read most of the google answers and I have been studying but I still do not have the entire picture.

Link to comment
Share on other sites

Hi David,

I would say yes and that you phrased it quite well. You can also recurse with repetitions - see here by Comment: http://fmforums.com/forum/topic/29250-poor-mans-recursive-function/. Custom Function would probably be fastest (if written well) because setting of variable or global would be eliminated (which scripts require).

Actually none of us has the entire picture although there are some here who get pretty darned close to understanding it all. Unfortunately I'm not one of them. :geek: yet

Link to comment
Share on other sites

There is only one thing I know to do, David ... I always create a null layout with no fields and I set in file options to load that layout at startup. Then if it crashes and I reopen file, I can drop into layout mode and go change the CF before returning to browse. I suppose you could also write a protection into your CF such as wrapping with If ( not gHalt ; your CF ...) where you can pre-fill with 1 at startup but I am unsure which would take place first ... Setting the global at startup or the CF evaluating on the layout last opened which is where the crash last left it. It is easier to set the opening layout to one without the fields. :-)

ADDED: Never run tests and re-use a GOOD file which has crashed. I re-use crashed test files only and never good files.

Link to comment
Share on other sites

This topic is 4206 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
×
×
  • Create New...

Important Information

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