Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
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%';
12 printBugNumber(BUGNUMBER);
13 printStatus (summary);
15 var r = Math.random;
16 var c = Math.pow( 2, 53 );
18 var n = 10000;
19 var odd1 = 0;
20 var odd2 = 0;
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 }
31 odd1 *= 100 / n;
32 odd2 *= 100 / n;
34 if (odd1 >= 47.5 && odd1 <= 52.5)
35 {
36 actual = expect;
37 }
38 else
39 {
40 actual = ' is ' + odd1.toFixed(3);
41 }
43 reportCompare(expect, actual, summary);
45 if (odd2 >= 47.5 && odd2 <= 52.5)
46 {
47 actual = expect;
48 }
49 else
50 {
51 actual = ' is ' + odd2.toFixed(3);
52 }
54 reportCompare(expect, actual, summary);