1 2 Previous Next 15 Replies Latest reply on Aug 6, 2009 7:40 PM by barefootguru

    Eek—Random function isn't



      Eek—Random function isn't

      Description of the issue

      Hi people, Every time I quit FileMaker and relaunch, and create 10 records (command-N or a looping script), I get exactly the same set of 'random' numbers. I've created a test database with a single numeric field called 'rand'.   The field is set to auto-enter a calculated value of 'Int(Random*100)'. Quit and relaunch, run looping script:  8784688217864183018Quit and relaunch, run looping script: 8784688217864183018 Quit and relaunch, hit command-N 10 times: 8784688217864183018 i.e. my database now has 30 records with repeated sets of 'random' numbers. My clients are running FMP 8.5 on various Macs and a server and are having problems on some of their machines, I'm running FMPA 10 on a Mac and having problems everytime. The same problem was mentioned in FileMaker Experts 'Random function not random at all'.  So, 1. This is a bug report 2. Any thoughts on a workaround?  I've been thinking of running an open script with dummy=random, repeated x times based off the system time, but either it'll be too predictable (using the seconds), or too slow (using the timestamp). Cheers  

        • 1. Re: Eek—Random function isn't



          Thank you for your post.


          I cannot duplicate the problem.  This is what i have done:


          1. I created a table with one field - "rand" - and set it to Auto-Enter a calculated value = Int (Random * 100)


          2. I created a script that does the following:


          Set Variable ( $var ; "1" )


             New Record/Request

             Set Variable ( $var ; $var + 1 )

             Exit Loop If [ $var > 10 ]

          End Loop


          3. I execute the script, and I get the results:













          4. I quit FileMaker Pro 10, relaunch FileMaker Pro 10, open the database and run the script with the following results:















          Further running of the script yields new results.


          Let me know what I'm doing differently than you, and I'll set up my database to try and reproduce it.



          FileMaker, Inc. 

          • 2. Re: Eek—Random function isn't

            Hey TSGal, thanks for looking into this.


            It looks like you've repeated everything correctly, though make sure you are restarting FileMaker before every run of the script--that's when the sequence restarts.


            I've just tried it on my iMac here and it is random, but my MacBook Pro is not.  Do you have some other machines you can try it on?


            MBP is 2.33 GHz Intel Core 2 Duo, OS X 10.5.6, FMP10A

            iMac is 2.4 GHz Intel Core 2 Duo, OS X 10.5.6, FMP10A


            The database is at http://www.tomrobinson.co.nz/downloads/random.fp7.zip and has the first 2 runs from my MBP--note the numbers are repeated after record 10. 


            The steps are:


            1. Quit FileMaker 

            2. Open random.fp7

            3. Run make script 

            4. Quit FileMaker 

            5. Open random.fp7

            6. Run make script 


            Check the last 2 sets of 10 records to see if the numbers are repeated.



            • 3. Re: Eek—Random function isn't



              After trying it on six different machines, we could duplicate the problem.  We don't know what is the common denominator, but three of the machines were MacBook Pro, all running OS X 10.5.5 and FileMaker Pro 10 Advanced, and one of those machines was able to duplicate the problem.


              At this point, we are reporting it to Development and Software Quality Assurance (Testing) departments so they are aware of this issue.  When the cause is found, I will let you know.



              FileMaker, Inc. 

              • 4. Re: Eek—Random function isn't

                Thanks for making the effort TSGal, good to hear you could reproduce it.


                For now I'm going to patch my solution to include the timestamp in the random call but would like to hear if you find the trigger.


                I'm impressed by these forums--it's a much more user-oriented system than the black hole of the online FM bug/feedback reporting. 

                • 5. Re: Eek—Random function isn't



                  As reported  on the FMExperts board and reported to FM in December, I can reproduce same on Vista but not XP or OSX10.4.11 on G5 Dual


                  Hope this helps



                  • 6. Re: Eek—Random function isn't

                    barefootguru wrote:

                    I'm impressed by these forums--it's a much more user-oriented system than the black hole of the online FM bug/feedback reporting. 

                    Definitely. This is a big step forward in user relations.


                    • 7. Re: Eek—Random function isn't

                      There's another bug with the random function - I don't know if it's known or verified. Sometimes the random function returns values that are 1e+20 times larger than they should be. This is with 10.0v1 on Leopard 10.5.6. 


                      Here's a wrapper function that works around against both these bugs.  



                      // myRandom

                      // FM10v1 sometimes returns a random number up to 1e+20 instead of up to 1. This wrapper function protects against that bug. 

                      // This also works around a bug that might produce the same sequence of random numbers every time FM is started

                      // http://forum-en.filemaker.com/fm/board/message?board.id=aut&thread.id=927




                          Rnd = Random ;

                          Rnd = Case( Rnd > 1; Rnd/1,0e+20; Rnd)


                      Mod ( Rnd * Get( CurrentTimestamp ) ; 1 )





                      Edit: Having problems with code formatting

                      • 8. Re: Eek—Random function isn't
                           Thanks macsolve.  I originally tried to workaround the 'repeating' random bug by including the timestamp but found my UUID custom function was still returning occasional duplicates.  I guess it's to do with starting with a fixed set of values (the 'random' ones), multiplying by a monotonically increasing number (the timestamp), and then truncating the result (e.g. int(rnd*4))
                        • 9. Re: Eek—Random function isn't



                          I reported this on another thread, and forgot to do so here.  Sorry about that.


                          There is a problem with the seed generator on machines with more than one active network interface card, and that seems to be causing the non-random results.  No additional information is available at this time.



                          macsolve - I have been unable to return a value greater than 1 (I only tried it a few times with 10,000 records).  How often do you return this value?  Can you tell me more about your computer?  That is, Mac/Windows, version of OS, cards installed, other software running, etc.?





                          FileMaker, Inc.

                          • 10. Re: Eek—Random function isn't


                            I get results that are 100000000000000000000 times too large (i.e. 1e+20) but only sometimes on a white MacBook with MacOS X 10.5.6. It has stock ethernet and airport cards (both active last time the issue occurred), and additional logical network ports defined (for example Parallells creates a few logical network ports).  


                            I haven't been able to track down a pattern where the large results happen, a few days ago at work I got it consistently but when I try to reproduce it now I only get normal results below 1. Right now only the Airport card is active. Next time at work I will experiment with if a connected ethernet port matters for this issue. 



                            Johan Sölve 

                            • 11. Re: Eek—Random function isn't

                              Regarding the large random numbers, I have had the issue again now. It showed up when I opened a rather large database file (almost 400 MB) that has originally been converted from FM6, while being connected to both ethernet and airport networks. 

                              It looks just like the decimal comma (that's what my Swedish locale uses as decimal separator) is missing from the result, i.e.


                              instead of


                               making the result 1e+20 times too large.  


                              I tried to duplicate the issue again after disconnecting the ethernet cable and connecting it again, but haven't seen it again so far. 

                              • 12. Re: Eek—Random function isn't

                                macsolve wrote:

                                I tried to duplicate the issue again after disconnecting the ethernet cable and connecting it again, but haven't seen it again so far. 

                                Now I can reproduce the issue reliably on my computer. It is triggered by a fairly complex substitute calculation with about 200 substitutes within one substitute function call, i.e. using the syntax substitute("input";["1";"replace 1"];["2";"replace 2"];...). 


                                I tried a test database with a custom function with 200 dummy substitutes but that didn't reproduce it. I'll try to boil it down somehow.


                                I haven't verified it on another machine yet, but I've verified that the network cards aren't involved as the issue happens no matter if I use ethernet or just airport. 


                                • 13. Re: Eek—Random function isn't

                                  My colleague David found the culprit. It's a call to a custom function that uses SmartPill to call the PHP function preg_replace. 

                                  Here's a test database that shows the error with too large random numbers.



                                  You need Smartpill 1.5 or 2.0 (maybe older versions as well). 


                                  I'll report this to the Smartpill folks as well, but it's very surprising that a FileMaker extension can affect built in functions like this.  


                                  Johan Sölve 

                                  • 14. Re: Eek—Random function isn't
                                    The folks at Smartpill figured out that the real reason for the problem was that I set the locale to Swedish in my custom function for regular expressions using Smartpill/PHP, by using the LC_ALL category. This seems to trip up the FileMaker internals so it doesn't "see" the decimal separator from the random function. I assume this would affect other decimal calculations in FM as well.   
                                    The reason I set the locale is so the preg_replace function treats our extended characters properly for example when using the \w character class in a regular expression. Since I really only need to set the locale for text characters I can use the LC_CTYPE, leaving the locale setting for numbers (LC_NUMBER) alone. This fixes the issue. 
                                    Relevant php code that sets the locale: 
                                    setlocale (LC_CTYPE, 'sv_SE.ISO8859-1');
                                    It seems that FileMaker should make sure that the correct locale is used everywhere, even if a plugin sets a different locale for its own use. Who knows if changing the locale for text characters using LC_CTYPE trips up something else internally in FM?
                                    Here's a new test file that has the fixed locale setting, so it has a Random function that works properly. 
                                    Btw we only saw the issue on Mac, not Windows.  
                                    1 2 Previous Next