How to get "randbetween" numbers that change only once per hour

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.

2X_6_6085de0e4d7bcf4cfe7284530e1ed8b3bb931e54.png

3 4 540
4 REPLIES 4

Here’s a formula I use in an action to “randomly” (or so it would seem), pick a number between 1 and 6 to write to a cell. This in turn is used to choose one of 6 sets of random numbers for the ordering of records in a UX (hence, a “shuffle” function that only works when it is intentionally invoked):

if([Number]=mod(second(timenow()-“00:00:00”)+1,6)+1,mod([Number]+3,6)+1,mod(second(timenow()-“00:00:00”+1),6)+1)

The if() structure is designed to prevent the shuffle from picking the same number as last time.

We made an app where it needs to show different image every hour and every day for one week. The solution was something like… WEEKDAY(TODAY())&LEFT(TEXT(TIMENOW()),2)&".png"

That’s almost exactly what I’m doing in my app now. The only difference is that mine doesn’t have to follow predetermined order.

Yes that’s true… but does it make any harm? With this way you can be sure that the same question is not shown twice for example in a day or in a week. Just a thought.

Top Labels in this Space