Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-211590.js

raw symbols SCIP
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/. */
5
6 var gTestfile = 'regress-211590.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 211590;
9 var summary = 'Math.random should be random';
10 var actual = '';
11 var expect = 'between 48% and 52%';
12
13 printBugNumber(BUGNUMBER);
14 printStatus (summary);
15
16 var r = Math.random;
17 var c = Math.pow( 2, 53 );
18
19 var n = 10000;
20 var odd1 = 0;
21 var odd2 = 0;
22
23 for ( var i = 0; i < n; ++i )
24 {
25 var v= r() * c;
26 if ( v & 1 )
27 ++odd1;
28 if ( v - c + c & 1 )
29 ++odd2;
30 }
31
32 odd1 *= 100 / n;
33 odd2 *= 100 / n;
34
35 if (odd1 >= 48 && odd1 <= 52)
36 {
37 actual = expect;
38 }
39 else
40 {
41 actual = ' is ' + odd1.toFixed(3);
42 }
43
44 reportCompare(expect, actual, summary);
45
46 if (odd2 >= 48 && odd2 <= 52)
47 {
48 actual = expect;
49 }
50 else
51 {
52 actual = ' is ' + odd2.toFixed(3);
53 }
54
55 reportCompare(expect, actual, summary);