I’ve made an app for language learners and I’ve set it up to display one of 123 “inspirational” quotes in the opening view. Until now I’ve used the following expression to do this:
randbetween(2,124)
(This is between 2 and 124 because 1 is reserved for the first time someone opens the app after downloading it.)
Recently, however, I’ve noticed that the messages that’s displayed changes suddenly while I’m looking at it. I think this has to do with syncing activity that’s happening in the background; the syncing seems to cause a new random number to be produced.
To fix the problem, I’ve decided to have the app randomly switch the message that is displayed once an hour. I could go from 2 to 124 in order but I thought it would be nice to add an element of “randomness” (or at least perceived randomness) to the selection of the quote. Here’s what I came up with:
mod((year(now())*month(now())*day(now()))/(hour(timenow()-“00:00:00”)+1),123)+2
I tested the equivalent formula on a spreadsheet and it seems to be more-or-less random. In my test I generated about 26,000 numbers with this method and all of the numbers between 2 and 124 came up a few hundred times. The max() was 302 and the min() was 100 instances; not exactly random but pretty close. So, I think I’m going to use this. I thought I’d post about it here in the “Tips & Tricks” section in case anyone else would like to add some variety to their displays but wants to avoid the frequent abrupt changes that can be caused by RandBetween() expressions.
Finally, just remember: Everything is practice.
