Random Select with Probabilities

Hi there,

I am trying to build an app that randomly selects an item from a list (fruits) based on a given probability. So, what it should be doing is the following:

Press Button
Returns “Hi you won a Apple”

I read this previous post which suggests to use the math.js plugin.

I think I found the math.js formula I need which should be this
math.pickRandom(array, weights)

However, I have no idea where to create a list of fruits and how to assign them a probability of being selected.

After that, how do you link this simple workflow to a button?

Thank you to all of you for your help!

use :random item on your search.

…:random item

Returns a random item from the list. Randomness is not guaranteed. The return may be biased in some way, so this is mostly for display purposes.

Hi grottofilms,

Thanks for the answer, is there any way to make the random selection process linked to a set of weighted probabilities chosen by me?

not that I know of with vanilla bubble. you might be able to do it with a plugin

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