{"library":"pandemonium","title":"Pandemonium","description":"Pandemonium is a lightweight JavaScript and TypeScript library providing a collection of common random-related utility functions. Currently stable at version 2.4.1, it offers functionalities such as `choice` for selecting random items, `random` for generating numbers within a range, `shuffle` for array randomization, and various specialized sampling algorithms like `reservoirSample` and `geometricReservoirSample`. A key differentiator is its modular design, allowing users to create custom versions of any function by injecting a specific random number generator (RNG) source, enabling seeded or otherwise controlled randomness. The library emphasizes performance for its sampling methods, offering detailed complexity analysis. Its release cadence is not explicitly stated in the provided documentation, but the package appears actively maintained with regular updates.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pandemonium"],"cli":null},"imports":["import choice from 'pandemonium/choice';","import { choice } from 'pandemonium';","import { createRandom } from 'pandemonium/random';","import { shuffle } from 'pandemonium';","import type { RandomBooleanFunction } from 'pandemonium/random-boolean';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { choice, random, shuffle } from 'pandemonium';\nimport { createRandom } from 'pandemonium/random';\nimport seedrandom from 'seedrandom'; // Ensure 'seedrandom' is installed: npm install seedrandom\n\n// Basic usage of random utilities\nconst fruits = ['apple', 'banana', 'cherry', 'date'];\nconsole.log('Random fruit:', choice(fruits));\n\nconst randomNumber = random(10, 20); // Integer between 10 and 20 (inclusive)\nconsole.log('Random number (10-20):', randomNumber);\n\nconst numbersToShuffle = [1, 2, 3, 4, 5];\nconst shuffledNumbers = shuffle(numbersToShuffle); // Returns a new shuffled array\nconsole.log('Shuffled numbers:', shuffledNumbers);\n\n// Demonstrating custom RNG for reproducible results\nconst seed = 'my_secret_seed';\nconst seededRNG = seedrandom(seed); // Create a seeded RNG function\n\n// Create a custom random function using the injected seeded RNG\nconst reproducibleRandom = createRandom(seededRNG);\n\nconsole.log(`\\nReproducible random numbers with seed \"${seed}\":`);\nfor (let i = 0; i < 3; i++) {\n  console.log(`  Run ${i + 1}:`, reproducibleRandom(1, 100));\n}\n\n// Verify reproducibility by creating another instance with the same seed\nconst anotherSeededRNG = seedrandom(seed);\nconst anotherReproducibleRandom = createRandom(anotherSeededRNG);\nconsole.log(`Reproducible random numbers (second run with same seed \"${seed}\"):`);\nfor (let i = 0; i < 3; i++) {\n  console.log(`  Run ${i + 1}:`, anotherReproducibleRandom(1, 100));\n}","lang":"typescript","description":"This quickstart demonstrates basic random number and selection utilities like `choice`, `random`, and `shuffle` from Pandemonium. It also illustrates a key feature: how to integrate a custom random number generator (e.g., `seedrandom`) to create reproducible random sequences, which is essential for testing or specific application needs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}