MCPcopy Create free account
hub / github.com/ampproject/amphtml / selectRandomItem

Function selectRandomItem

src/experiments/index.js:278–281  ·  view source on GitHub ↗

* Selects, uniformly at random, a single item from the array. * @param {string[]} arr Object to select from. * @return {?string} Single item from arr or null if arr was empty.

(arr)

Source from the content-addressed store, hash-verified

276 * @return {?string} Single item from arr or null if arr was empty.
277 */
278function selectRandomItem(arr) {
279 const rn = RANDOM_NUMBER_GENERATORS.accuratePrng();
280 return arr[Math.floor(rn * arr.length)] || null;
281}
282
283/**
284 * Selects which page-level experiment branches are enabled. If a given

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected