# Saving a list of numbers

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.

1 Like

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:

Random Number (bubbleapps.io)

2 Likes

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.

1 Like

@GaryIreland whatās your app name, I can give you a plugin for it

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

okay click āAdd pluginā and it should be at the top of the list

1 Like

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.

2 Likes

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.