Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

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

Recommended Posts

Posted (edited)

I use the following calculation:

Int((Random * 499) + 1)

I would like to know if it is possible to make the random number that appears to be no less than a set number in another field? so for example if the set number is 200 it can be any number between 499 and 200 but not 199 or less.

Also when I use that calculation the field for all records gets filled inmediately. Is there a way for the field to be filled only when I pass through each record?

Any help is much appreciated. I am a beginner at best and use FM 5.5

Edited by Guest
Posted

Here's a general formula for generating a random number between LOW and HIGH (inclusive):

LOW + Int ( Random * ( HIGH - LOW + 1 ) )

I am not sure I understand your second question. You can have a script loop thru records and set a number field to the calculation's result, if you so prefer.

Posted

Ill try that formula. Thanks.

Let me give you an example to explain my second question:

I have set the calculation for random number. What I want is that instead of that field being filled in every record inmediately after defining the field, I want that field to be filled only when I go to an individual record and put the cursor on that field.

Posted

Also when I use that calculation the field for all records gets filled inmediately. Is there a way for the field to be filled only when I pass through each record?

Are you trying to say you don't want it to calculate a value until after you put a value in the low value?

If so then surround it in a case statement

case( not isempty( fieldName ), TrueValue, FalseValue )

in this case the fieldName is the field with your low value the TrueValue would be the equation Comment provided and I would simply leave the last , and False Value off so it looks like

case( not isempty( fieldName ), equation )

Posted (edited)

Are you trying to say you don't want it to calculate a value until after you put a value in the low value?

If so then surround it in a case statement

case( not isempty( fieldName ), TrueValue, FalseValue )

in this case the fieldName is the field with your low value the TrueValue would be the equation Comment provided and I would simply leave the last , and False Value off so it looks like

case( not isempty( fieldName ), equation )

No. The low value was a different question. What I mean is when I put the random calculation in "define field" and press save the field gets filled with a random number in every record of the database. What I need is some variation of that calculation so that when I press save that field is not filled automatically but only when I go to a record and choose that field.

Edited by Guest
Posted

without knowing anything else I would probably not use a calculation and instead use a script and place a button pointed to the script either next to the field or make the field itself a button.

So your script would end up being

setfield[ yourField; your equation ]

Posted

Here's a general formula for generating a random number between LOW and HIGH (inclusive):)

LOW + Int ( Random * ( HIGH - LOW + 1 ) )

so in the place of LOW I would put the name of the field containing the low number?

Posted

without knowing anything else I would probably not use a calculation and instead use a script and place a button pointed to the script either next to the field or make the field itself a button.

So your script would end up being

setfield[ yourField; your equation ]

I am sorry but you lost me. I am a beginner with this program. One more thing is that I would have to be able to convert the field back to being a basic number field.

Posted

that formula doesn't work. Any other way to make the random number be equal or bigger than the minimum number in another field (every record has a different minimum number)?

Posted

I have posted about this problem before because I posted two questions at the same time it became confusing.

Let me try and explain this step by step:

I have a database with 100 records. Every record has a number field. I want to fill that field with a random number so I use the following calculation:

Int((Random * 499) + 1)

To do that I go to "Define Fields", I highlight the number field, I change the type from number to calculation, I press save, a box that says the following:

"When changing the field type to Calculation or Summary, FileMaker will replace any data in the field with the result of the formula. Proceed anyway?"

I press "OK" and the "specify calculation" box appears. I enter:

Int((Random * 499) + 1)

and press "OK". That takes me back to the "Define Fields" box. I press "done" and then every record has the number field filled by a random number.

BUT what I would like is that when I go to a record and press on the number filled thats when it gets filled AND NOT automatically after pressing "done".

Am I making any sense? I hope someone can help. Thank you.

Posted

that formula doesn't work.

This doesn't tell us much. Do you not get a random number? Are they out of the range? What is the exact calc you ended up using?

Posted

This looks like an extension of your previous thread.

It sounds like you just need to populate the random number field with a button click? If so, change your field back to a Number and define a script with a Set Field[] script step having your random calc as the source and your field as the target. Then define a button with a Perform Script, selecting your new script as the script to run.

Posted

This doesn't tell us much. Do you not get a random number? Are they out of the range? What is the exact calc you ended up using?

I apologise, I should have given details. I use the formula given to me by comment:

LOW + Int ( Random * ( HIGH - LOW + 1 ) )

Low being the minimun number and high being 499. The problem is not the range. It does give me a number between the minimum and 499. The problemis that records with high minimum numbers get a high random number. Those with low minimum numbers get lower random numbers. It defeats the purpose of getting a random number

Posted

Hmm, you don't the results because it gives different random numbers than what you were hoping for?? If you don't believe the distribution is fair, you can set up a test file with a script to loop through n iterations for various ranges.

Posted

Hmm, you don't the results because it gives different random numbers than what you were hoping for?? If you don't believe the distribution is fair, you can set up a test file with a script to loop through n iterations for various ranges.

I have tried this formula 20 times:

LOW + Int ( Random * ( HIGH - LOW + 1 ) )

The "random numbers" I get are high for records with high minimums and get progressively smaller on records with lower minimums.

I tried this formula another 20 times:

Int((Random * 499) + 1)

The "random numbers" I get are evenly given. There are record with high minimums that have a high random number, there are records with high minimums that have a low random number, there are records with a low minimum that have a high random number and thereare records with a low minimum that get a low random number.

So the first formula is not truly random, the second is, but the seconds does not acheive what I want. Is there any other calculations that would work?

And what is this script thing. I am not familiar with scrpits. Any chance of step by step help please?

Posted

The "random numbers" I get are evenly given. There are record with high minimums that have a high random number, there are records with high minimums that have a low random number, there are records with a low minimum that have a high random number and thereare records with a low minimum that get a low random number.

Huh? Nevermind.

You should reexamine your process, because the algorithm is sound. If you don't want to take my word for it, try the attached sample.

RandomTest.fp5.zip

Posted

Huh? Nevermind.

You should reexamine your process, because the algorithm is sound. If you don't want to take my word for it, try the attached sample.

In your example it works. Any way to do that test with different low numbers for each record?

It should work in my database. Any reasons why it wouldn't?

Posted

Any way to do that test with different low numbers for each record?

Sure, define high and low to be regular number fields instead of globals.

It should work in my database. Any reasons why it wouldn't?

That's hard to say without access to your database.

Posted (edited)

Sure, define high and low to be regular number fields instead of globals.

That's hard to say without access to your database.

this is so strange. Let's try another way maybe. Let's say I put my calculation in without worrying about minimums

Int((Random * 499) + 1)

all records get a random number. I then tranform this field back into a number field. Is there a calculation that I can then put in the random number field so that the random number in each record is equal to its minimum if it was of lesser value?

Edited by Guest
Posted

Huh? Nevermind.

You should reexamine your process, because the algorithm is sound. If you don't want to take my word for it, try the attached sample.

I think the problem is that using this formula:

LOW + Int ( Random * ( HIGH - LOW + 1 ) )

the random number is calculated between high (499) and the minimum.

This formula on the other hand:

Int((Random * 499) + 1)

calculates the random number between 1 and 499

That's why I get high random numbers for records with high minimums.

I probably explained myself badly, but what I need is for the random number to be calculated between 1 and 499. Now lets say a record with a minimum of 200 gets 100. That then needs to be corrected so it gets 200

Posted

This looks like an extension of your previous thread.

It sounds like you just need to populate the random number field with a button click? If so, change your field back to a Number and define a script with a Set Field[] script step having your random calc as the source and your field as the target. Then define a button with a Perform Script, selecting your new script as the script to run.

So I would be able to click record by record and only fill those I want? Could you please show me how? I do appreciate your patience. I have explained myself pretty badly and my FM knowledge is extremely limited.

Posted

This is very confusing.

what I need is for the random number to be calculated between 1 and 499

Then you should make LOW = 1 and HIGH = 499.

But then you go on to say that the minimum needs to be 200. So why would you need to generate numbers below 200? If you set LOW = 200, the numbers are going to be distributed evenly in the 200 - 499 range.

Posted

This is very confusing.

Then you should make LOW = 1 and HIGH = 499.

But then you go on to say that the minimum needs to be 200. So why would you need to generate numbers below 200? If you set LOW = 200, the numbers are going to be distributed evenly in the 200 - 499 range.

your formula is correct, I just explained myself badly. if a record has a minimum of 200 then with your formula it would calculated between 200 and 499. If I put 1 as low and 499 as high it would calculate in that range.

But is there a way to calculate a random number anywhere between 1 and 499 and then if the number is lesser than the minimum change it to be EQUAL to the minimum?

Posted

Weird... but:

Let(RanNum = LOW + Int ( Random * ( HIGH - LOW + 1 ) );

If(RanNum < DEFAULT ; DEFAULT ; RanNum)

)

Where LOW is your low barrier (e.g. 1), where DEFAULT is the number your checking against e.g. 200 and where high is the higher barrier.

Posted

Yes, of course there is a way:

Max ( MINIMUM ; Int ( Random * 499 ) + 1 )

But this means that in a large number of records, about 40% of the records will be assigned the value of 200. The remaining 60% will have random values between 200 - 499. I cannot imagine why you would want that, but...

Posted

Weird... but:

Let(RanNum = LOW + Int ( Random * ( HIGH - LOW + 1 ) );

If(RanNum < DEFAULT ; DEFAULT ; RanNum)

)

Where LOW is your low barrier (e.g. 1), where DEFAULT is the number your checking against e.g. 200 and where high is the higher barrier.

This is what I put in as the calculation:

Let(RanNum = 1 + Int ( Random * ( 499 - 1 + 1 ) );

If(RanNum < Minimum ; Minimum ; RanNum)

)

I get this error message:

"either an operator was omitted,this function cannot be found, or "[" was not expected here"

What did I do wrong?

Posted

Yes, of course there is a way:

Max ( MINIMUM ; Int ( Random * 499 ) + 1 )

But this means that in a large number of records, about 40% of the records will be assigned the value of 200. The remaining 60% will have random values between 200 - 499. I cannot imagine why you would want that, but...

But every record has a different minimum so to arbitrarily assign 200 in 40% of the cases would be no good.

Posted

I merged your the two topics.

I will send a private topic to juanito2006 about splintering or double posting.

Lee

Posted

I merged your the two topics.

I will send a private topic to juanito2006 about splintering or double posting.

Lee

why? It was two different things (even though closely related) and this post is getting so complicated already :

Posted

Yes, of course there is a way:

Max ( MINIMUM ; Int ( Random * 499 ) + 1 )

I get this error:

"either an operator was omitted,this function cannot be found, or "[" was not expected here"

Posted

First you need to define a field to hold the minimum value for each record. Only then you could use the formula:

Max ( MINIMUM ; Int ( Random * 499 ) + 1 )

where MINIMUM is the name of your field.

Now, the 200 is only an example. The point is that the random numbers will not be distributed uniformly over time. Using only Int ( Random * 499 ) + 1, the probability of drawing any number between 1 and 499 is equal. Using Max ( 200 ; Int ( Random * 499 ) + 1 ) the probability of getting 200 is approximately 40% - because any random number below 200 will be changed to 200.

This topic is 6677 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.