
1. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
BruceHerbach Mar 12, 2014 3:13 PM (in response to Polarpro)My guess is FileMaker. I did a test run. Created a field with the formula Ceiling (random * 6) The ran a loop that created 10000 records. Well actually ran the script twice so 20000 records. At the end of this I had 3300 records with a value of 6 and 0 records with a value of 0.
As a test I created 20000 records with the formula random. The lowest value I got was 0.002xxxx with several more digits after the 2. So based on this, it will be very rare that you would get an actual 0.
If you rounded the random function to 2 digits, you would get a 0.
HTH
Bruce

2. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
Polarpro Mar 12, 2014 3:42 PM (in response to BruceHerbach)Hey Bruce,
Thanks for running this test!
So, if the lowest value you get is greater 0, then FileMaker's description would be wrong, as they state that 0 is included.

3. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
user19752 Mar 12, 2014 5:12 PM (in response to Polarpro)1 of 1 people found this helpfulYou are right.
But getting 0 by test is too hard since if the Random function is really random
then the result to be 0 only probability about 1/10^16.
If you need 1 to 6, using Ceiling() is bad.
Floor(Random*6)+1 must be 1 to 6, never get 0.

4. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
Polarpro Mar 13, 2014 2:27 AM (in response to user19752)Ok, Thank you, that makes sense. I created a script to have a look at the random numbers and got numbers that had 20 decimal places  to hit exactly 0.00000000000000000000 seems to be very unlikely indeed

5. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
Stephen Huston Mar 13, 2014 12:33 PM (in response to Polarpro)Polarpro wrote:
in FileMaker 12 Training Series they ask for the result of the following function:
Ceiling ( Random * 6 )
The solution according to the Training Series is:
A random integer from 1 to 6
That seems to me not correct.
You are forgetting the effect of the Ceiling function, which is what FM wanted evaluated. Ceiling returns the number inside the function rounded up to the next integer, so the smallest return is 1.
The Random function itself is defined in help as "Returns a number between zero and one, including zero, but not including one." The catch is that the decimal can be so close to 1 that it rounds to 1 for calculation purposes. When multiplied by another integer, display rounding could make it report as 6, but the real number behind it will be some tiny amount below 6, with 6 as the ultimate ceiling figure.
The Ceiling function forces it into the 1...6 range.

6. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
BruceHerbach Mar 13, 2014 2:41 PM (in response to Stephen Huston)To twist this a bit, if you wanted integer values from 0 to 6, the formula round(random * 6;0) will provide this.

7. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
user19752 Mar 13, 2014 8:47 PM (in response to Stephen Huston)No.
Random function "Returns a number between zero and one, including zero, but not including one.",
when it returns zero, Ceiling(0*6) results zero.
It is veeery rare case so you may not see, but using the expression to get a number from 1 to 6
cause a bug which can't reproduce.
Bruce, if you want 0 to 6, there are 7 values so start thinking from Random*7.
Your expression returns 0 and 6 on half probablity than 1 to 5. It is not good usually.

8. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
BruceHerbach Mar 13, 2014 9:51 PM (in response to user19752)Probably I should have said 0 through 6. By using the Round function instead of Ceiling you get all 7 values. The function coice depends on the range of values you want.

9. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
user19752 Mar 14, 2014 12:02 AM (in response to BruceHerbach)I mean if you use the expression many times, you will get 1(and 2,3,4,5) twice as 0(6).
Random*6
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 5.99999
Round(Random*6;0)
0....1..........2..........3..........4..........5..........6....
0 has range of 0.0...0.499999 (width is 0.5)
1 has range of 0.5...1.499999 (width is 1)

10. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
Stephen Huston Mar 14, 2014 4:33 PM (in response to user19752)user19752 wrote, in part:
No.
Random function "Returns a number between zero and one, including zero, but not including one.",
when it returns zero, Ceiling(0*6) results zero.
It is veeery rare case so you may not see....
You are quite correct about this, but since decimal fractions with the random function are carried out to 20 places, I think the chances of returning a string of
0.00000000000000000000
is approaching zero probability.
Wait! I know it's not equal to zero probability, and I have to agree, if one relied on it absolutely never coming up with a zero result, some risk remains.
I think my assumption about the zero result not appearing is due to the way Random has been seeded in the past so that the results are not really random, they just appear that way  if one doesn't execute it enough times to notice patterns.
Just out of curiosity, does anyone know enough about the random function to suggest odds for
Ceiling ( Random ) = 0

11. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
DavidJondreau Mar 14, 2014 9:29 PM (in response to Stephen Huston)1 in 10^20? That's roughly the chance of picking out a particular grain if sand from all the beaches on Earth.
Interestingly, Random doesn't seem to return a consistent number of digits. It varies between at least 18 and 23.

12. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
BruceHerbach Mar 15, 2014 8:03 AM (in response to Stephen Huston)There was a time in version 9 if my memory is accurate where on a specific model MacBook Pro, Random would return the exact same sequence of results. So on that computer it wasn't random at all. I had that model MacBook and had the opportunity to demonstrate the issue to some people from FileMaker. The issue was fixed in the next release. At the time there was quite a lot of discussion about the issue on technet and it was reported as a bug.
Just a tidbit from the past.
Bruce

13. Re: Ceiling ( Random * 6 ) (Excercise in FM Training Series)
Stephen Huston Mar 18, 2014 11:42 AM (in response to BruceHerbach)I recall that discussion. It stemmed in part from the mistaken belief some people held that random and unique had something to do with each other, and the mistaken assumption that the Random function could be used to generate unique numbers for Keys/IDs, back before we had the UUID function. The fact that Random numbers could repeat seemed to surprise some, but the fact that they repeated each time a random sequence was triggered on some machines really did prove it was a bug  not random at all.