The source array to pick an element from
A randomly selected element from the array
const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
RandomGenerator.pick(colors); // e.g. "blue"
RandomGenerator.pick(fruits); // e.g. "apple"
// Select random configuration options
const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
const randomLocale = RandomGenerator.pick(['en', 'ko', 'ja', 'zh']);
// Choose random test scenarios
const testScenario = RandomGenerator.pick([
'happy_path',
'edge_case',
'error_condition',
'boundary_test'
]);
// Random user role assignment
const userRole = RandomGenerator.pick(['admin', 'user', 'moderator']);
// Select random API endpoints for testing
const endpoints = ['/users', '/posts', '/comments', '/categories'];
const randomEndpoint = RandomGenerator.pick(endpoints);
Randomly selects a single element from an array.
Chooses one element at random from the provided array using uniform distribution. Each element has an equal probability of being selected. This is a convenience function equivalent to sampling with a count of 1, but returns the element directly rather than an array containing one element.