# Generating random decimal

Hello!

I have a list of users with a field each which is called “Number”.

Every user has a different value (number) in their “Number”. But I want to add a random decimal to that number everytime I press the button “save”.

for instance:

user 1 Number = 2
user 2 Number = 5
user 3 Number = 7

press “save”

user 1 Number = 2,3
user 2 Number 5,7
user 3 Number = 7,2

How would I go about creating this?

Thanks for help!

1 Like

Yes, I tried your plugin. But I need to generate multiple random decimals everytime the page loads to assign to the different users.

Is that possible @Bubbleboy?

Have you tried using the bubble create calculation?

1 Like

I was thinking the something similar. Though I noticed the Bubble generate random string is meant only for whole numbers. So you’d need to do a quick transformation to make it a decimal. But Bubble treats the generate random string as text within the expression builder.

@jakob.askling does the number have to be a decimal or can it be an integer? If so, that may make for an easier solution.

1 Like

What if you assign a random number that is the same as was previously assigned?

What is the problem you are trying to solve?

Altering properties of multiple users on page load is not generally a good pattern, especially for performance.

1 Like

@mishav makes a good point. Your app would slow with many users.

You could convert the random numbers to a string by running it through `parseFloat()` using the one of the js plugins.

Before I found the bubble random string function I used time to create a number that wouldn’t burn resources. Specifically seconds and miliseconds.

Are you going to be performing math on these float values?
Do you want to use just one decimal?

1 Like

@jakob.askling not mine just for completeness… created by Airdev

1 Like

Hello!

I will explain to the best of my ability. I have a list of users (list no.1) and each has a value of either 1,2,3 or 4 (a field). They are sorted in that list based on the numerically so all “one” comes first and the “two” etc.

My program takes users from that list (list no.1) and put them into another list (list no.2). But the list no.2 will always take the, for instance, first, third and fifth item from list no.1. But I need those users that list no.2 picks from list no.1 to be different each time. The first, third and fifth item on list no.1 must be different users each time. But the users in list no.1 must also always be sorted 1,2,3,4.

If I add a random decimal to their original value, for instance, 3 --> 3,4, they would shuffle around. But still, be sorted after their original value 1,2,3,4

Example:

(User 1) value = 1,2
(User2 ) value =1,4
(User 3) value =1,7
(User 4) value =2,3
(User 5) value =2,4
(User6 ) value =2,7
(User 7) value =3.2
(User8 ) value =3,5
(User 9) value =3,7
(User 10) value =4,2
(User 11) value =4,3

And because of that list, no.2 would pick different users every time from list no.1

Thanks for explaining further.

I don’t understand what “value” represents, can you give it a less abstract field name? For example, “Queue”, “Category”, “Seat”, “Runway”, “Rank”, “LotteryPick”. Is it purely a mechanism for ranking/sorting? Or a mechanism for picking the second list?

Can you give more meaning to “list1” and “list2”? For example, “list1” users are employees, “list2” users are employees who worked overtime this week.

Are you wanting to take one list of users, and randomly pick half of them into a second list? If so, you might want to use the `:random` list function, which picks a random item.

One problem you’ll face, is that generating a set of random numbers between 1 and 4 doesn’t guarantee that you’ll get different numbers in specific positions of the set, or even guarantee a different set. Although over a large number of iterations it gives some sort of distribution, each time you generate you might get a distribution you don’t like, for example all 1’s.

Another problem is what to put in the sort expression, having two sort values in one field makes it harder than having a separate field for each value.

I hope this helps.

1 Like

What will initiate decimals added to th re-order?

@mishav is correct - The chances of you ending up with multiple variants of just 9 random integers are pretty good. If this is for re-positioning users within a list, there are other ways that might not require this workaround.

This topic was automatically closed after 70 days. New replies are no longer allowed.