michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 211590; michael@0: var summary = 'Math.random should be random'; michael@0: var actual = ''; michael@0: var expect = 'between 47.5% and 52.5%'; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var r = Math.random; michael@0: var c = Math.pow( 2, 53 ); michael@0: michael@0: var n = 10000; michael@0: var odd1 = 0; michael@0: var odd2 = 0; michael@0: michael@0: for ( var i = 0; i < n; ++i ) michael@0: { michael@0: var v= r() * c; michael@0: if ( v & 1 ) michael@0: ++odd1; michael@0: if ( v - c + c & 1 ) michael@0: ++odd2; michael@0: } michael@0: michael@0: odd1 *= 100 / n; michael@0: odd2 *= 100 / n; michael@0: michael@0: if (odd1 >= 47.5 && odd1 <= 52.5) michael@0: { michael@0: actual = expect; michael@0: } michael@0: else michael@0: { michael@0: actual = ' is ' + odd1.toFixed(3); michael@0: } michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: if (odd2 >= 47.5 && odd2 <= 52.5) michael@0: { michael@0: actual = expect; michael@0: } michael@0: else michael@0: { michael@0: actual = ' is ' + odd2.toFixed(3); michael@0: } michael@0: michael@0: reportCompare(expect, actual, summary);