|
1 /* |
|
2 * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * The original NIST Statistical Test Suite code is placed in public domain. |
|
16 * (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) |
|
17 * |
|
18 * This software was developed at the National Institute of Standards and Technology by |
|
19 * employees of the Federal Government in the course of their official duties. Pursuant |
|
20 * to title 17 Section 105 of the United States Code this software is not subject to |
|
21 * copyright protection and is in the public domain. The NIST Statistical Test Suite is |
|
22 * an experimental system. NIST assumes no responsibility whatsoever for its use by other |
|
23 * parties, and makes no guarantees, expressed or implied, about its quality, reliability, |
|
24 * or any other characteristic. We would appreciate acknowledgment if the software is used. |
|
25 */ |
|
26 |
|
27 #include "openc.h" |
|
28 #include "../include/externs.h" |
|
29 |
|
30 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
31 F R E Q U E N C Y T E S T |
|
32 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
33 |
|
34 void |
|
35 Frequency(int n) |
|
36 { |
|
37 int i; |
|
38 double f, s_obs, p_value, sum, sqrt2 = 1.41421356237309504880; |
|
39 |
|
40 sum = 0.0; |
|
41 for ( i=0; i<n; i++ ) |
|
42 sum += 2*(int)epsilon[i]-1; |
|
43 s_obs = fabs(sum)/sqrt(n); |
|
44 f = s_obs/sqrt2; |
|
45 p_value = erfc(f); |
|
46 |
|
47 fprintf(stats[TEST_FREQUENCY], "\t\t\t FREQUENCY TEST\n"); |
|
48 fprintf(stats[TEST_FREQUENCY], "\t\t---------------------------------------------\n"); |
|
49 fprintf(stats[TEST_FREQUENCY], "\t\tCOMPUTATIONAL INFORMATION:\n"); |
|
50 fprintf(stats[TEST_FREQUENCY], "\t\t---------------------------------------------\n"); |
|
51 fprintf(stats[TEST_FREQUENCY], "\t\t(a) The nth partial sum = %d\n", (int)sum); |
|
52 fprintf(stats[TEST_FREQUENCY], "\t\t(b) S_n/n = %f\n", sum/n); |
|
53 fprintf(stats[TEST_FREQUENCY], "\t\t---------------------------------------------\n"); |
|
54 |
|
55 fprintf(stats[TEST_FREQUENCY], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); |
|
56 fprintf(results[TEST_FREQUENCY], "%f\n", p_value); |
|
57 } |