How many potential quotations do you have?
For example, if you have 100, then you could allocate them a Foreign Key from 1 to 100. Them create a global field as the primary key, and allocate a random number between 1 and 100 whenever you want (file open, layout load, whev...) and show the now matching Quotation Record.
It will vary, but likely between 2-6. It may change though as we add or subtract from them (no set number for sure). I guess it could go more and more if we keep adding. I'm trying to personalize so each user can enter his or her own number and then randomly get a favorite.
PS When you say "allocate a random number" is that self-generated or is it a script?
I did just find this: Selecting a random set of records | FileMaker
- 1. Define a new number field called "RandomField"
- 2. Define a script with these steps:
Show All Records
Replace Field Contents [No Dialog, MyFile::RandomField, Random]
Sort Records by RandomField [No Dialog]
Go to Record/Request/Page [First]
Omit Multiple Records [No Dialog, 10]
Show Omitted Only
2 of 2 people found this helpful
It might be easier to do this as a calculation field. Trying to do it with relationships or portal filtering gets tricky.
A calculation could be:
Let ( [
number = round ( Random * 100 ; 0 ) + 1 ;
result = GetNthRecord ( relatedQuotes::Quote ; number )
1 of 1 people found this helpful
Using the method that you just found--which is essentially the same as shuffling a deck of cards, you could set up a relationship using the cartesian join operator (X) to match to all records and put a 1 row portal using a sorted portal or sorted relationship to sort the records by the field with the random number. Any time you want a new quote to appear, you run the example script again.
Okay, I think I follow! I will try to combine all that is said and report back! (I do have Advanced.)
1 of 1 people found this helpful
I do believe that this will fail on rare occasions. Random can return 0, when it does, you'll get 0 as a result, not 1.
*And n will be underrepresented by the same frequency.
To avoid the "0" result, why not just add ".1" to every random number that is generated, before turning it into an integer?
Well, you'd have to add .000000000000000001 not .1 since Random returns a result to 20 decimal places. Just make sure you're counting those zeros correctly!
Dude, it's a bad day to rock my world. But thanks anyway.
So, I guess it should be Floor ( ( Random * n ) + 1 ) ?
(or what you said - I'm not in testing mode right now.)
I like Floor() between than my earlier post of Round(). I don't see any issues with Floor() + 1.
Random gives a number between 0 and 1 including zero but not one, which is why Floor beats Ceiling.
Thanks again for pointing that out.
To me, it's more significant than it is minute.
Okay, finally able to get around to sorting this out. I understand the Floor calculation for getting a random number, now HOW do I combine that with something else to display a random record from a table? There is the "Selecting a random record" script I initially posted, but then someone said not to do it in a script but as a calculation ... but then where do I do that calculation and how do I display? This may be a simple thing I am just missing, would much appreciate connecting the dots. Thanks!