MCPcopy
hub / github.com/ampproject/amphtml / getRandom

Function getRandom

src/3p-frame.js:322–334  ·  view source on GitHub ↗
(win)

Source from the content-addressed store, hash-verified

320 * @return {string}
321 */
322export function getRandom(win) {
323 let rand;
324 if (win.crypto && win.crypto.getRandomValues) {
325 // By default use 2 32 bit integers.
326 const uint32array = new Uint32Array(2);
327 win.crypto.getRandomValues(uint32array);
328 rand = String(uint32array[0]) + uint32array[1];
329 } else {
330 // Fall back to Math.random.
331 rand = String(win.Math.random()).substr(2) + '0';
332 }
333 return rand;
334}
335
336/**
337 * Returns the custom base URL for 3p bootstrap iframes if it exists.

Callers 2

getSubDomainFunction · 0.70
generateSentinelFunction · 0.70

Calls 1

StringFunction · 0.50

Tested by

no test coverage detected