Random Generator

Content Type: Module
Categories: Utility

Overview

You can generate random numbers, text, password or value that you want with custom length easily.

Documentation

Typical usage scenario


Random Generator gives you five JavaScript actions that produce random values on the client: a numeric string of a given length, a random integer between two bounds, random letters, a random password, and a random string drawn from any character set you supply. Each one is a single nanoflow activity with one or two parameters — no entity to create, no configuration, no server call.


Use it wherever your app needs a throwaway value and you do not want to write the loop yourself:


• Generate a reference or booking code. Call Generate Random Text with a length of 8 and uppercase only, and you have EBLKEWMK — a code that is readable over the phone and free of case confusion.

• Suggest a starting password. Generate Random Password draws from letters, digits and the punctuation set !+-*/_.?, so a "suggest a password for me" button on a registration or reset screen becomes one activity.

• Build a mixed-format key or SKU. Generate Random takes your own character set — pass ABCDEFGHJKLMNPQRSTUVWXYZ23456789 to exclude the characters people mistype, or a hex alphabet to produce a hex token.

• Pick a random item from a list. Random Number Between gives you an index to select against, which is the usual need behind a "show me a random tip", "rotate the banner" or "pick a demo record" feature.

• Seed demo and test data. Fill a form with plausible junk in a nanoflow before a demo, or generate distinct names during a load test, without touching your production logic.

• Produce a numeric OTP-style string. Generate Random Number builds a digits-only value of the length you ask for, which is the shape most one-time-code screens expect.


The problem it solves is small but real: Mendix has random() in expressions, which returns a decimal between 0 and 1, and nothing else. Every code, token or password ends up as a hand-rolled loop over a character set in a nanoflow, repeated in every app. This module makes it one activity — and, importantly, makes the character set explicit so you can see exactly what your codes are made of.


Features and limitations


Five JavaScript actions


• Every action is platform-neutral. All five run in web, responsive and native nanoflows alike.

• Character sets are visible and documented. You are not guessing what a "random password" contains — the exact 70-character alphabet is listed above.

• Custom alphabet support. Generate Random is the general case: any string you pass becomes the pool, so excluding ambiguous characters, restricting to hex, or generating from a non-Latin alphabet is a parameter change rather than a code change.

• No domain model. The module ships no entities and no attributes, so there is nothing to migrate, secure or clean up. Results come back as nanoflow variables.

• Included example. An Example nanoflow calls all five actions in sequence with sample arguments, wrapped in Nanoflow Commons ShowProgress / HideProgress.

• npm dependency is bundled. The js-random-generator package (v1.0.4, MIT) ships inside the package, so no network access is needed at build or run time.


Dependencies


• Mendix Studio Pro 10.24.17 or higher.

• No Marketplace module dependency for the actions themselves. All five JavaScript actions are self-contained.

• The Example nanoflow requires Nanoflow Commons. It calls NanoflowCommons.ShowProgress and HideProgress. Nanoflow Commons ships with every new Mendix app, so this is normally already present; if your app does not have it, the Example nanoflow will show consistency errors. Delete or exclude it, or install Nanoflow Commons from the Marketplace.

• No Java actions, no JAR dependencies, no widgets.


Installation


1. In Studio Pro 10.24.17 or higher, open App Explorer > Import module package and select RandomGenerator.mpk.

2. Run Update project directory if prompted.

3. In a nanoflow, add a JavaScript action activity and pick the action you want from the RandomGenerator module.

4. Open RandomGenerator.Example to see all five actions called with sample arguments.


If the Example nanoflow shows errors after import, your app is missing Nanoflow Commons — the example uses its ShowProgress / HideProgress actions. Either install Nanoflow Commons from the Marketplace or exclude the Example nanoflow. The five generator actions themselves are unaffected.


If you hit a "cannot find module 'js-random-generator'" error, confirm that javascriptsource/randomgenerator/actions/node_modules/js-random-generator is present in your project directory. Re-importing the package restores it; do not run npm install in that folder, as the bundled copy is the tested version.


Configuration

There is nothing to configure at module level. Choose the action, pass the parameters.


Known bugs


• The Generate Random documentation string reads "Generate random number with character set". Cosmetic only — the action generates a random string from any character set you pass, not a number. The behaviour is correct; the description is not.


Two functional defects present in 2.0.0 and earlier are fixed in 2.0.1: Random Number Between ignored its lower bound and returned values from 0, and Generate Random Number could return fewer digits than requested. Upgrading is recommended if you are on an earlier version.


Frequently Asked Questions


Can I call these from a microflow?

No. They are JavaScript actions and run client-side in a nanoflow. Call the nanoflow from your microflow.


Do they work in a native mobile app?

Yes. All five actions are marked for all platforms and use no browser-specific API.


Is this safe for generating security tokens or API keys?

No. The underlying library uses Math.random(), which is not cryptographically secure and is predictable given enough output. Use it for reference codes, demo data and list indices. Generate anything security-sensitive server-side.


Do I need to run npm install?

No. js-random-generator v1.0.4 ships inside the module package, so builds work offline. Do not replace it with a fresh install — the bundled copy is the version this release was tested against.


Do I need any other Marketplace module?

Not for the actions. The bundled Example nanoflow uses Nanoflow Commons ShowProgress / HideProgress, which is present in every new Mendix app; if yours lacks it, exclude the example.


Why does Random Number Between never return my minimum?

That was a defect in 2.0.0 and earlier, caused by a type coercion that discarded the lower bound. Fixed in 2.0.1 — min is now honoured, including a min of 0.


Why is my four-digit random number sometimes only three digits?

That was a defect in 2.0.0 and earlier — the value was built as a digit string that could start with zero, and the Integer return type dropped it. Fixed in 2.0.1: the leading digit is never zero, so the length is always exactly what you asked for.


Does Generate Random Password guarantee a digit and a special character?

No. Each character is drawn independently from the full 70-character set, so short passwords often miss a class. Use a length of 12 or more, and validate against your policy separately if you need guarantees.


Are generated values unique?

No. Nothing tracks previous output. Over 1,000 four-digit calls, 44 collided. Check against your data and retry if uniqueness matters.


Can I use emoji or accented characters in a custom character set?

Accented Latin characters are fine. Emoji and other characters outside the Basic Multilingual Plane are not — the library indexes by UTF-16 code unit and will produce broken half-characters.


Why does the module show version 1.0.0 in Studio Pro?

The module-level version metadata was not bumped when the package was rebuilt. The release is 2.0.1; the discrepancy is cosmetic and has no runtime effect.


Which Studio Pro versions are supported?

10.24.17 and higher. This release was converted from 9.24.18 for the 10.24.17 LTS line and published as tag Version2.0.1.


Issues, suggestions and feature requests:

https://github.com/bharathidas/RandomGenerator/issues

Releases

Version: 2.0.0
Framework Version: 10.24.17
Release Notes:

**Random Generator** — Studio Pro **10.24.17**


### Fixed


**`randomNumberBetween` ignored the lower bound.** Asking for a number between 5 and 10 returned 0–4. Mendix passes Integer parameters as `big.js` objects whose `valueOf()` returns a string, so the underlying library's `Math.random() * (max - min) + min` concatenated `min` instead of adding it, and `Math.floor` then discarded the appended digits. Verified over 20,000 iterations before and after. A minimum of `0` also works correctly — the library's own `if (!min)` guard would have rejected it.


**`generateRandomNumber` returned fewer digits than requested.** The value was assembled as a digit string that could begin with zeros; the Integer return type then dropped them, so roughly one call in ten came back short. The leading digit is now never zero, and the result always has exactly the requested number of digits.


Both defects predate the 10.24.17 upgrade — they are present in Version2.0.0 and in the earlier 9.24.18 package. **Upgrading is strongly recommended.**


### Known remaining behaviour

- `generateRandomPassword` makes no guarantee that a password contains a digit, an uppercase letter or a symbol. Validate the result if you need a character-class policy.

- `max` is exclusive in `randomNumberBetween`.

- Values are derived from `Math.random()` and are not cryptographically secure. Do not use them for tokens, keys or session identifiers.


### Notes

Studio Pro 10.24.17, imports with 0 errors. Import `RandomGenerator.mpk` via *App Explorer > Import module package*.

Version: 1.0.0
Framework Version: 9.24.18
Release Notes: You can generate random numbers, text, password or value that you want with custom length easily. **Features** • **generateRandom**- Generate random number with character set. • **generateRandomNumber**- Generate a random number (custom length). • **generateRandomPassword**- Generate a random password (custom length). • **generateRandomText**- Generate a random text (Upper and Lower case). • **randomNumberBetween**- Generate a random number between (min,max). **Dependencies**: • Mendix modeler 9.24.18. **Issues, suggestions and feature requests** [https://github.com/bharathidas/RandomGenerator/issues](https://github.com/bharathidas/RandomGenerator/issues) **Screenshots**: ![Screenshot_1](https://github.com/user-attachments/assets/3402236d-e7dd-42f7-8017-81042947d6be)