Forum Academy Marketplace Showcase Pricing Features

[NEW PLUGIN] Random Number Generator

Hi all,

We’ve published a new (free) plugin called Random Number Generator. This will allow you to generate a random number based on a minimum and maximum value (can be static or dynamic). Number can be generated automatically on page load or through a workflow action.

If any bugs, issues, or questions come up please email [email protected] or reply to this thread. Happy Bubbling!

David
AirDev - Custom Software for Everyone

9 Likes

Here’s a simple whac-a-mole game that we built by using this plugin. Enjoy! See if you can get 20 points :smiley:

2 Likes

Easier said than done! :joy: Awesome game!!

2 Likes

Cant get it to work, no guides either

If you visit this page:

You’ll see some setup instructions at the bottom of the page, including a link to the editor as a demo setup (you’ll need to be logged in to view).

2 Likes

Thanks Luke bit will it generate a UNIQUE random number every time?

The number generated is more or less random, but should not be used for things like generating passwords or API keys.

From Mozilla’s explanation of the function used inside this plugin:

Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security. Use the Web Crypto API instead, and more precisely the window.crypto.getRandomValues() method.

If you need to do the above, we can look into updating the plugin to have a different “Secure random number” workflow.

2 Likes

thanks Andersan but my question was specifically if it will generate a unique id because I am using it to assign to an identifier. I think there is a possibility that a random number can again be generated, so do you reckon that this would not be a suitable number generator to assign to a unique identifier column?

Hi there, @kmeenakshi26… when saving a field to the db, there is a Calculate formula option that can have a type of Generate random string.

As you can see in the screenshot, you can specify the number of characters to include in the string, and you can select other parameters, too. Now, I’m guessing there is always a chance that no matter how many characters the string has and what other parameters it includes, the system could generate the same string more than once. That being said, the chances would likely be so small (depending on how you configure the string generator) that maybe it would work for you? Just a thought… hope it helps.

Best…
Mike

2 Likes

One option to prevent two objects from being assigned the same ID would be checking whether another another object already has the same ID.

If there is another object with that ID, you could generate another one and assign it to the object.

Mike is right that with enough characters (e.g. 12 non-case sensitive alphanumeric characters) you should not run into duplicate IDs. With 12 alphanumeric characters (0-9 and A-Z) there are over a billion possible IDs that could be generated.

2 Likes

Thanks Mike, I may actually take that chance. If I were to search for an ID in the entire DB before assigning, that will be a hit on system performance. so I may do away with that thought. I have implemented it as you have shown here. Thanks again

2 Likes

Thanks Andersan, If I were to search for an ID in the entire DB before assigning, that will be a hit on system performance so I am not planning to do that. I may just take the chance of an odd error being thrown in case it has a duplicate ID

1 Like

Hey David - thanks for making this. It’d be helpful to include some documentation on the format of the number that gets returned. Is it a random integer generator? Or does it generate a random number with fixed set of places after the decimal?

Hey @Brenner , looking at the plugin’s code there are 2 flows:

  1. element on the page which generates a random integer
  2. server side workflow which generates a random number

The random number does not have a fixed set of places after the decimal. However, with Bubble’s “formatted as…” property, you can take that number and limit the number of decimal places it has, which usually seems to be 14+.

Here’s the JS function used in both of these Bubble workflows: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

How do I generate a boolean True/False value with this?