I am trying to create a random card generator. In this case, the card is just a piece of text, which I call prompts. So I have a type called “black card” and a super long list (2500) of prompts.
I created a rectangle with dynamic text that says Search for Black Cards:random item’s Prompt. Under that I put a button that refreshes the page.
This is my solution but it sucks. The reason being that the prompts take so long to show up. I’m talking like 10 seconds. I’m assuming because it is searching for all 2500 prompts and then picking a random one. Is there a solution to this?
I also would like the button to show the next random prompt rather than refresh the whole page. How can I do that?
There is calculate formula feature if you just need to create digits every time user press the button
Sorry I’m sort of new to Bubble so I may be missing it. But how does creating digits help me generate a new random prompt on the page?
I think the idea is that if you have 2500 things, when the user presses the button it generates a random number between 1-2500.
Then you just need to hit the database and retrieve the item number based on the random digit.
So if I press the button, random number = 435. Then the workflow will just fetch record number 435 from the black cards list.
Should speed it up.
Okay, so do I need to add a field where every prompt has a number? How do I do that other than manually?
No, you can just use this plugin to generate a random number:
So in your workflow, user clicks the button and you generate a random number from 1 to “do a search for cards: count”. Then the final part will be to display card in the text group e.g display data in group (do a search for cards: item number “random generator number result”)
Thanks! That sounds doable for me
Okay I was able to do the first part.
The second part I’m not sure how to do. I created a text group but I’m not sure what to put as the source. I don’t know how to pull the number generated from the button.
I think I’m making progress. I bound that you have to go to the button workflow to display data in a certain group. I still don’t know how to pull the random number generated by the button. Here’s a picture of where I am. What do I there?
Yep almost there.
To get the number you just select that drop down in the screen shot “result of step 1 random number…”
That will then send the data to the group. Then you just put the text element inside the group and select the text to be “parent groups black cards title” (I’m assuming title here, depends on your column name for text thing)
That did it! I don’t know why I got stuck there. Thanks Dan!
I tried doing this and while it works perfectly - i tried tracking the “rolled number”. The Random generator was showing the correct number but after displaying data, the number changed like for example: Random Generator showed 42 but it returned a 28.
Also, i set the Maximum in the Random Generator to what you said as in Erick’s issue which is “search for…: count” and it was going beyond the the number of data i have (which is only 50). I decided to set the Max manually to 50 and this worked. But the number being returned after displaying data was not accurate at all.