Forum Documentation Showcase Pricing Learn more

[confirmed]Bug with :random or doing it wrong

Hi all,

I have a group on my index page that has a source Search for Customer_Items:random item and this correctly loads a random item when the page is opened.

I am trying to update this group with a new random item every 15 seconds, but cannot get it to work repeatably.

The first method I tried was to use the “Do every” event in the workflow coupled with the “Show Data in Group” which has the same source query as when the page loads. No success.

The second method I tried was to use the “Do every” to increment a custom state counter every 1 second, and a “Do when condition is true” to watch for the value hitting 15, then “Show Data in Group” and then reset the custom state counter to 0. This is a partial success as it updates the group after the first timer interval, but then stops updating the group for subsequent triggers.
Edit: I have also noticed that the 2nd update is always the first item in the database that matches the criteria.

I thought it might have something to do with caching or other stuff, so tried to show/hide and also reset group. All made no difference.

What specifically do I need to do, to reload the group with a new random item very x seconds.

Thanks,
:confused:

1 Like

Ok, I think this is a confirmed bug, and I’ll take it to the Bug reporting.

I created this demo app, and :random appears to work fine UNTIL you apply a criteria to the search. in the demo, picking a random from Simple list which is simple a record with the letter of the alphabet and corresponding number e.g. a 1, b 2 etc. you will see that the random with criteria, appears to get stuck on specific values, a, e and i when the criteria is set for number < 13.

https://dave-auld-demo-stuff.bubbleapps.io/version-test/randomitemdemo?debug_mode=true

Looks like the :random is broken.

Regards,
Dave

1 Like

Also looking for a workaround/fix.

I too encountered this bug. I was trying to “search for a thing : random item”, but was always getting the same instance of a “thing” back.

Bug Context:
-I found this is the case if you do this in a “workflow” while trying to “set state” on an element.
-I had no “criteria” set on the query.

Solution for me:
I was able to put the same “search for a thing : random item” in the “Data Source” for a “Group” container, and then the randomization started working.

Hope it helps…
Sagan

The solution I use is when performing a search, sort it randomly, then select a random item.

2 Likes

@Scott, is that with a criteria set? as that is when the bug shows as you can see from my demo app.

1 Like

Thanks Scott, I just tried that on my demo app and works perfectly as a work around.

Do you get still get a random result if selecting the first item from the random sort? It’d be more efficient.

Edit: the random sort would likely be done at the database layer, so a different algorithm used to the :random function.

I have added both to my demo and both approaches work, I ran it for about 40 iterations on a timer and the distribution looks comparable with both approaches.

Here is the page running with the different approaches.

I’m glad it worked for you! I checked out your demo but didn’t get a chance yet to try it out for your case.

1 Like

It definitely would be more efficient, except I believe I was still getting non-random appearing results. This was for something I’ve done about a year ago though, so there’s a possibility something might have changed.

Dave, that is a nice way to show the differences.

Have you compared :random on a client-only workflow vs a server one (that stores into the database)?

No, not done that, but would need to pull the data once and then filter locally, that would be fine for small datasets, but not for large ones.

I’m having a similar issue. I have a page that has a parameter in the URL. The parameter is the ID for fields in the database. There is a button that reloads the same page but sets a new ID as the parameter in the URL. The parameter entry is set to search for a random ID, and is filtered to exclude the current one in the URL. Unfortunately, the button isn’t very random because it switches between the two same IDs every time the button is clicked.

1 Like

Do the same thing as the work around, Do a search for Id excluding the existing one, then sort in the query criteria by Random, then back at the data source definition, do a :first or :random and see how that works for you.

hi @DaveA having the same problem even sorting it randomly, it gives me same results everytime i click a button, can you share us your workflow?

Here is the link to the editor, you can switch into wokflow and pick it off from there.

thanks it seems that what i did is correct, the only problem why it didn’t work because i only have 4 data inside my Thing so what i did is add more then boom its working now…

so it means to be make the :random work, you need atleast 5 data inside your Thing

I ran into this bug too. I tested with 9 data and the bug remained. I bumped it to 26 data and the bug went away. This was using both “random sorting” and “random item:”.

Haven’t yet tested a “random sorting” / “first item:” combo. I suspect this will use less resources?

I’m having the same issue with randomization. The only way I can achieve it is by refreshing the page - resending data to a group doesn’t re-randomize.