Skip to content

Commit 5985043

Browse files
committed
Merged PR 48369: Replace Math.random to getRandomValues() from cryptoObj
1 parent f0ff2af commit 5985043

File tree

7 files changed

+136
-22
lines changed

7 files changed

+136
-22
lines changed

demo/v2-demo/scripts/guid.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function generateNewGuid() {
77
d += performance.now();
88
}
99
return 'xxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
10-
// Generate a random number, scaled from 0 to 16.
11-
// Bitwise-and by 15 since we only care about the last 4 bits.
12-
const r = (d + Math.random() * 16) & 15 | 0;
10+
11+
// Generate a random number, scaled from 0 to 15.
12+
const r = (getRandomValue() % 16);
1313

1414
// Shift 4 times to divide by 16
1515
d >>= 4;

demo/v2-demo/scripts/utils.js

+10
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,14 @@ function removeArgFromUrl(url, arg) {
230230
}
231231

232232
return url;
233+
}
234+
235+
function getRandomValue() {
236+
237+
// window.msCrypto for IE
238+
var cryptoObj = window.crypto || window.msCrypto;
239+
var randomValueArray = new Uint32Array(1);
240+
cryptoObj.getRandomValues(randomValueArray);
241+
242+
return randomValueArray[0];
233243
}

demo/v2-demo/syntaxHighlighter/syntaxhighlighter.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi-client.d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/*! powerbi-client v2.10.1 | (c) 2016 Microsoft Corporation MIT */
22
declare module "util" {
33
import { HttpPostMessage } from 'http-post-message';
4+
global {
5+
interface Window {
6+
msCrypto: Crypto;
7+
}
8+
}
49
/**
510
* Raises a custom event with event data on the specified HTML element.
611
*
@@ -40,7 +45,7 @@ declare module "util" {
4045
*/
4146
export function assign(...args: any[]): any;
4247
/**
43-
* Generates a random 7 character string.
48+
* Generates a random 5 to 6 character string.
4449
*
4550
* @export
4651
* @returns {string}
@@ -81,6 +86,10 @@ declare module "util" {
8186
* @returns {boolean}
8287
*/
8388
export function isRDLEmbed(embedUrl: string): boolean;
89+
/**
90+
* Returns random number
91+
*/
92+
export function getRandomValue(): number;
8493
}
8594
declare module "config" {
8695
const config: {

dist/powerbi.js

+86-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)