regress-211590.js (1054B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 //----------------------------------------------------------------------------- 7 var BUGNUMBER = 211590; 8 var summary = 'Math.random should be random'; 9 var actual = ''; 10 var expect = 'between 47.5% and 52.5%'; 11 12 printBugNumber(BUGNUMBER); 13 printStatus (summary); 14 15 var r = Math.random; 16 var c = Math.pow( 2, 53 ); 17 18 var n = 10000; 19 var odd1 = 0; 20 var odd2 = 0; 21 22 for ( var i = 0; i < n; ++i ) 23 { 24 var v= r() * c; 25 if ( v & 1 ) 26 ++odd1; 27 if ( v - c + c & 1 ) 28 ++odd2; 29 } 30 31 odd1 *= 100 / n; 32 odd2 *= 100 / n; 33 34 if (odd1 >= 47.5 && odd1 <= 52.5) 35 { 36 actual = expect; 37 } 38 else 39 { 40 actual = ' is ' + odd1.toFixed(3); 41 } 42 43 reportCompare(expect, actual, summary); 44 45 if (odd2 >= 47.5 && odd2 <= 52.5) 46 { 47 actual = expect; 48 } 49 else 50 { 51 actual = ' is ' + odd2.toFixed(3); 52 } 53 54 reportCompare(expect, actual, summary);