Randomize Any
A secure randomization utility library that provides various randomization functions, supporting both browser and Node.js environments. You can find it on npm: randomize-any.
Features
🔒 Secure Random: Uses
crypto.getRandomValues()for cryptographically secure random number generation🎯 Multiple Types: Supports randomization of array elements, integers, and floating-point numbers
⚖️ Weight Support: Built-in weighted random algorithms
🌐 Cross-platform: Supports both browser and Node.js environments
📦 Multiple Formats: Provides ESM, CJS, UMD and other module formats
🔧 TypeScript: Complete TypeScript type definitions
Installation
npm install randomize-anyOr using pnpm:
pnpm add randomize-anyUsage
Basic Import
import { randomizeAny, randomizeInteger, randomizeFloat } from 'randomize-any';API Documentation
randomizeAny(list: any[]): any
Randomly select an element from an array.
Parameters:
list- The array to randomly select from
Returns:
A random element from the array
Example:
randomizeInteger(min: number, max: number): number
Generate a random integer within the specified range.
Parameters:
min- Minimum value (inclusive)max- Maximum value (inclusive)
Returns:
A random integer within the range
Example:
randomizeFloat(min: number, max: number): number
Generate a random floating-point number within the specified range (precision: 0.01).
Parameters:
min- Minimum value (inclusive)max- Maximum value (inclusive)
Returns:
A random floating-point number within the range
Example:
getSecureWeightedRandom(weights: number[]): number
Generate a secure random index based on a weight array.
Parameters:
weights- Weight array
Returns:
A random index based on weight distribution
Example:
Advanced Usage
Combined Usage
Generate Random Data
Browser Support
This library uses the crypto.getRandomValues() API to provide cryptographically secure random numbers. Supported browsers include:
Chrome 11+
Firefox 21+
Safari 3.1+
Edge 12+
IE 11+
For unsupported environments, it automatically falls back to Math.random().
Module Formats
This package provides multiple module formats:
ESM:
dist/index.browser.esm.mjsCommonJS:
index.jsUMD:
dist/index.browser.global.jsLegacy versions: Compatible versions with polyfills
Development
Websites Using This Library
Here are some websites and applications that use randomize-any in production:
🎮 Gaming & Entertainment
Colorfle Unlimited - A color wordle use the random algorithm to select daily target color randomly.
Flagle Explorer - A flag wordle select daily flag randomly by using weighted randomization.
🎯 Utilities & Tools
Ruleta Aleatoria - Simple web app helping users make random choices
Random Wheel from 1 to 100 - Tool for randomly selecting numbers from 1 to 100 using secure randomization algorithms
Want to showcase your website here? Open an issue or submit a pull request!
Last updated