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 :joy:

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 :slight_smile:

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

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.

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 :rofl: :rofl:

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. :slight_smile:

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.