I want to put a large list of numbers into the database to reference it later. Say the range from 0-10,000. Is there anyway to do that? I have a data type with a single field for list of numbers and I just want one entry for that data type and to not have to manually type 10,001 numbers
Whatās the purpose of this large list of numbers?
I want to pull random numbers from it but also Iām just curious now if it can be automated even if thereās a better way to do rng
There are much easier (and less costly) ways to generate random numbers than thatā¦
But if you really want to create a list of numbers in the database, then just run a recursive backend workflow 10,000 times, to create one database entry each time.
Thats terrifying
Good learning exercise to learn how to use recursive workflows i guess.
Ok well thanks for both lol. Good to know a backend workflow could do it but also Iāll try to figure out better ways.
If you are looking to generate a random number between 1 and 10000 you can use the :calculate formula operator and select āgenerate random stringā. Specify 4 as the number of characters and only check the āuse numbersā checkbox. Then use the :converted to number operator to convert it to an int type which you can use as a random number.
It will be between 0-9999 so you could add 1 to make it between 1 and 10000, or just keep as is.
Let us know if you are using the list of numbers for something else as well. But if its just for generating a random number then the above method is much simpler
That sounds good can I use it to do lists of random numbers without it being clunky? I was trying to set up a lotto. Tickets with idk say 100 numbers from a possible 10,000. The way I was going to do with was search for(database item with 10,000 numbers in a list) then randomise it and list the first 100 numbers.
As @nico.dicagno suggests, the simplest, and most Bubble way to do this is with the generate random string function (4 characters, numbers only), converted to Number.
That will give you a random number between 0 and 9,999, and adding 1 to the result will give you a random number between 1 and 10,000
Thereās no simple way to adapt that to give a number between 0 and 10,000 in vanilla Bubble, so if you really need that then using some simple JavaScript will be the easiest way.
Hereās an example of both methods:
Many ways to go about this, but this is how i would do it.
Create a Data Thing called Lotto Extraction.
Add a field for āWinning Numbersā as a list of numbers
Create a recursive backend workflow that uses the above mentioned method to generate a random number - Add it to the Winning Numbers field - reschedule the recursive workflow only if āThis Lotto Extraction - Winning Numbers - count - < desired winning numbersā (Desired winning numbers can be a hard coded static value or even a recursive workflow input)
Bubble lists cannot have duplicates when using the āaddā operator, so this self-handles the unlikely but possible scenario of a winning number being picked multiple times by the random number generator.
At the end you will have a list of winning numbers in the Lotto Extraction. And it will be saved to the database for future use.
Itās blowing my mind a little that a recursive workflow generating 100 random numbers every time someone takes a ticket is less costly on servers than randomly sorting a list of numbers already in the database.
Iāll definitely take you guys word for it but damn lol.
So yeah thank you I think that solves it. I can use the same method you described to pick the winning numbers to make the tickets.
While I have you guys here Iām struggling with doing the workflow to select the winning tickets(Iām actually morally certain Iāve solved this before and itās annoying). So I have a field for list of winning tickets and Iām trying to filter the total list of tickets for ones with numbers matching. But the search field for numbers is expecting a single number not a list so I get contains/doesnāt contain as an operator and canāt get it to filter for tickets with more than one winning number
Plugin is much easier, it can return the list you want easily in one action with some Javascript, what is your app name
ultimatelottery, itās not on a paid plan Iām just sandboxing trying to figure out the lottery elements before maybe nesting it in a bigger gambling app
Thank you! lemme check it out
To be completely fair, using Javascript to generate the list in one step is the best approach. Itās just not very bubble. It takes a few lines of very simple code and you would avoid having to run the recursive workflow.
That plugin is super handy @tylerboodman thank you.
Still canāt figure out how to filter a search of all tickets so itāll show me the winners. The ticket has a field with list of numbers but for some reason in this search the field seems to expect only one number.
Sounds like you assigned the users lotto numbers, now you need to pick a certain number of lotto numbers from everyoneās pool of lotto numbers? Or maybe Iām misunderstanding your structure.
The users all have tickets with 100 numbers. The draw has 100 winning numbers. I want to put all the tickets with matching numbers on the draws list of jackpot winners. Then also populate other lists with less matches.