
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
@smakss/random-array-element
Advanced tools
Efficiently select unique, non-repeating random elements from arrays with @smakss/random-array-element. Ideal for varied applications needing random but exhaustive array item selection.
Selecting a random element from an array is simple with Math.random()
. However, if you need to ensure that each element is only selected once until all elements have been chosen, @smakss/random-array-element
is the ideal solution. Utilizing closures, this package allows you to initialize a function once and then repeatedly obtain unique, randomly-selected elements from your array, without repeats until the array is exhausted.
You can check the working demo on RunKit.
or
Install the package using npm or Yarn:
npm i @smakss/random-array-element
# or
yarn add @smakss/random-array-element
To include it with CommonJS module you can do this:
const randomArrayElement = require('@smakss/random-array-element');
For ECMAScript modules:
import randomArrayElement from '@smakss/random-array-element';
Example usage:
// Initialize once for an array
const getRandomElement = randomArrayElement(['apple', 'banana', 'cherry']);
console.log(getRandomElement()); // Result: 'banana' (example output)
console.log(getRandomElement()); // Result: 'apple' (example output)
// ...after all items have been returned, it resets.
console.log(getRandomElement()); // Result: 'cherry' (example output)
// ...continues to return a new random item.
If an empty or non-array input is passed, the function will return -1, indicating no selection can be made:
const getRandomElement = randomArrayElement([]);
console.log(getRandomElement()); // Result: -1
Contributions are welcome! Please see CONTRIBUTING.md for guidelines and details.
To ensure a welcoming and safe community, our Code of Conduct outlines expected behaviors for all participants.
FAQs
Efficiently select unique, non-repeating random elements from arrays with @smakss/random-array-element. Ideal for varied applications needing random but exhaustive array item selection.
The npm package @smakss/random-array-element receives a total of 67 weekly downloads. As such, @smakss/random-array-element popularity was classified as not popular.
We found that @smakss/random-array-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.